0
Fork 0
mirror of https://github.com/TryGhost/Ghost.git synced 2025-02-10 23:36:14 -05:00

Added lint warnings for bad patterns in migrations

refs: https://github.com/TryGhost/Toolbox/issues/105
The idea here is to ensure we're at least warning on bad migrations patterns. If a pattern is already in use in an existing migration, we can use `eslint-disable-next-line no-restricted-syntax` to override it. For new migrations which still need these features this step will force the user to think about the performance of the construct they are using
This commit is contained in:
Sam Lord 2021-11-25 17:04:55 +00:00
parent 8c93bdff41
commit e28a3769a7

View file

@ -22,6 +22,38 @@ module.exports = {
'ghost/ghost-custom/max-api-complexity': 'error'
}
},
{
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.*/*'
]
},
{
files: 'core/server/data/migrations/versions/**',
rules: {
'no-restricted-syntax': ['warn', {
selector: 'ForStatement',
message: 'For statements can perform badly in migrations'
}, {
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: 'ForStatement ReturnStatement',
message: 'Invalid use of a return statement within for-loop in a migration'
}, {
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'
}]
}
},
{
files: 'core/shared/**',
rules: {