2021-05-07 22:25:50 +03:00
|
|
|
const path = require('path');
|
|
|
|
|
2021-05-07 12:30:41 +03:00
|
|
|
module.exports = {
|
|
|
|
env: {
|
|
|
|
es6: true,
|
|
|
|
node: true
|
|
|
|
},
|
|
|
|
plugins: ['ghost'],
|
|
|
|
extends: [
|
|
|
|
'plugin:ghost/node'
|
|
|
|
],
|
|
|
|
rules: {
|
|
|
|
// @TODO: remove this rule once it's turned into "error" in the base plugin
|
|
|
|
'no-shadow': 'error',
|
|
|
|
'no-var': 'error',
|
2023-05-02 23:43:47 +03:00
|
|
|
'one-var': ['error', 'never'],
|
|
|
|
'ghost/ghost-custom/ghost-error-usage': [1],
|
|
|
|
'ghost/ghost-custom/no-native-error': [1]
|
2021-05-07 15:21:22 +03:00
|
|
|
},
|
|
|
|
overrides: [
|
2021-05-07 22:41:14 +03:00
|
|
|
{
|
2022-07-04 15:21:29 +03:00
|
|
|
files: 'core/server/api/endpoints/*',
|
2021-05-07 22:41:14 +03:00
|
|
|
rules: {
|
2021-10-25 16:36:12 +03:00
|
|
|
'ghost/ghost-custom/max-api-complexity': 'error'
|
2021-05-07 22:41:14 +03:00
|
|
|
}
|
|
|
|
},
|
2021-11-25 20:04:55 +03:00
|
|
|
{
|
|
|
|
files: 'core/server/data/migrations/versions/**',
|
|
|
|
excludedFiles: [
|
|
|
|
'core/server/data/migrations/versions/1.*/*',
|
|
|
|
'core/server/data/migrations/versions/2.*/*',
|
|
|
|
'core/server/data/migrations/versions/3.*/*'
|
2021-11-29 18:04:38 +03:00
|
|
|
],
|
|
|
|
rules: {
|
2022-04-05 13:49:13 +03:00
|
|
|
'ghost/filenames/match-regex': ['error', '^(?:\\d{2}|\\d{4}(?:-\\d{2}){4})(?:-[a-zA-Z]+){2,}$', true]
|
2021-11-29 18:04:38 +03:00
|
|
|
}
|
2021-11-25 20:04:55 +03:00
|
|
|
},
|
|
|
|
{
|
|
|
|
files: 'core/server/data/migrations/versions/**',
|
|
|
|
rules: {
|
2022-05-10 10:14:05 +03:00
|
|
|
'no-restricted-syntax': ['error', {
|
2021-11-25 20:04:55 +03:00
|
|
|
selector: 'ForStatement',
|
|
|
|
message: 'For statements can perform badly in migrations'
|
2021-11-29 18:04:38 +03:00
|
|
|
}, {
|
|
|
|
selector: 'ForOfStatement',
|
|
|
|
message: 'For statements can perform badly in migrations'
|
|
|
|
}, {
|
|
|
|
selector: 'ForInStatement',
|
|
|
|
message: 'For statements can perform badly in migrations'
|
2021-11-25 20:04:55 +03:00
|
|
|
}, {
|
|
|
|
selector: 'WhileStatement',
|
|
|
|
message: 'While statements can perform badly in migrations'
|
|
|
|
}, {
|
|
|
|
selector: 'CallExpression[callee.property.name=\'forEach\']',
|
|
|
|
message: 'Loop constructs like forEach can perform badly in migrations'
|
|
|
|
}, {
|
|
|
|
selector: 'CallExpression[callee.object.name=\'_\'][callee.property.name=\'each\']',
|
|
|
|
message: 'Loop constructs like _.each can perform badly in migrations'
|
|
|
|
}, {
|
|
|
|
selector: 'CallExpression[callee.property.name=/join|innerJoin|leftJoin/] CallExpression[callee.property.name=/join|innerJoin|leftJoin/] CallExpression[callee.name=\'knex\']',
|
|
|
|
message: 'Use of multiple join statements in a single knex block'
|
2021-11-29 18:04:38 +03:00
|
|
|
}],
|
|
|
|
'ghost/no-return-in-loop/no-return-in-loop': ['error']
|
2021-11-25 20:04:55 +03:00
|
|
|
}
|
|
|
|
},
|
2021-05-07 15:21:22 +03:00
|
|
|
{
|
|
|
|
files: 'core/shared/**',
|
|
|
|
rules: {
|
2021-05-26 14:34:39 +03:00
|
|
|
'ghost/node/no-restricted-require': ['error', [
|
2021-05-07 15:21:22 +03:00
|
|
|
{
|
2021-05-07 22:25:50 +03:00
|
|
|
name: path.resolve(__dirname, 'core/server/**'),
|
2021-05-07 15:21:22 +03:00
|
|
|
message: 'Invalid require of core/server from core/shared.'
|
|
|
|
},
|
|
|
|
{
|
2021-09-30 16:59:01 +03:00
|
|
|
name: path.resolve(__dirname, 'core/frontend/**'),
|
2021-05-07 15:21:22 +03:00
|
|
|
message: 'Invalid require of core/frontend from core/shared.'
|
|
|
|
}
|
|
|
|
]]
|
|
|
|
}
|
2021-05-07 22:25:50 +03:00
|
|
|
},
|
2023-05-02 23:43:47 +03:00
|
|
|
{
|
|
|
|
files: ['core/frontend/helpers/**', 'core/frontend/apps/*/lib/helpers/**'],
|
|
|
|
rules: {
|
|
|
|
'ghost/filenames/match-regex': ['off', '^[a-z0-9-.]$', null, true]
|
|
|
|
}
|
|
|
|
},
|
2021-05-07 22:25:50 +03:00
|
|
|
/**
|
|
|
|
* @TODO: enable these soon
|
|
|
|
*/
|
|
|
|
{
|
|
|
|
files: 'core/frontend/**',
|
|
|
|
rules: {
|
|
|
|
'ghost/node/no-restricted-require': ['off', [
|
2021-10-16 18:30:09 +03:00
|
|
|
// If we make the frontend entirely independent, these have to be solved too
|
|
|
|
// {
|
|
|
|
// name: path.resolve(__dirname, 'core/shared/**'),
|
|
|
|
// message: 'Invalid require of core/shared from core/frontend.'
|
|
|
|
// },
|
2021-09-29 13:12:33 +03:00
|
|
|
// These are critical refactoring issues that we need to tackle ASAP
|
2021-05-07 22:25:50 +03:00
|
|
|
{
|
2021-10-19 20:41:02 +03:00
|
|
|
name: [path.resolve(__dirname, 'core/server/**')],
|
2021-05-07 22:25:50 +03:00
|
|
|
message: 'Invalid require of core/server from core/frontend.'
|
|
|
|
}
|
|
|
|
]]
|
|
|
|
}
|
|
|
|
},
|
|
|
|
{
|
|
|
|
files: 'core/server/**',
|
|
|
|
rules: {
|
2021-10-21 22:37:08 +03:00
|
|
|
'ghost/node/no-restricted-require': ['warn', [
|
2021-05-07 22:25:50 +03:00
|
|
|
{
|
2021-10-16 19:27:08 +03:00
|
|
|
// Throw an error for all requires of the frontend, _except_ the url service which will be moved soon
|
2021-10-19 20:41:02 +03:00
|
|
|
name: [path.resolve(__dirname, 'core/frontend/**')],
|
2021-05-07 22:25:50 +03:00
|
|
|
message: 'Invalid require of core/frontend from core/server.'
|
|
|
|
}
|
|
|
|
]]
|
|
|
|
}
|
2021-05-07 15:21:22 +03:00
|
|
|
}
|
|
|
|
]
|
2021-05-07 12:30:41 +03:00
|
|
|
};
|