mirror of
https://github.com/nodejs/node.git
synced 2024-11-27 22:16:50 +01:00
a596af0819
PR-URL: https://github.com/nodejs/node/pull/52592 Reviewed-By: Yagiz Nizipli <yagiz.nizipli@sentry.io> Reviewed-By: Jacob Smith <jacob@frende.me> Reviewed-By: Moshe Atlow <moshe@atlow.co.il>
50 lines
1.5 KiB
JavaScript
50 lines
1.5 KiB
JavaScript
'use strict';
|
|
|
|
const prefix = 'Out of ASCIIbetical order - ';
|
|
const opStr = ' >= ';
|
|
|
|
module.exports = {
|
|
meta: {
|
|
schema: [{
|
|
type: 'object',
|
|
properties: {
|
|
enforceTopPosition: { type: 'boolean' },
|
|
},
|
|
additionalProperties: false,
|
|
}],
|
|
},
|
|
create: function(context) {
|
|
const enforceTopPosition = context.options.every((option) => option.enforceTopPosition !== false);
|
|
return {
|
|
'VariableDeclaration:not(Program>:first-child+*) > VariableDeclarator[init.name="primordials"]'(node) {
|
|
if (enforceTopPosition) {
|
|
context.report({
|
|
node,
|
|
message: 'destructuring from primordials should be the first expression after "use strict"',
|
|
});
|
|
}
|
|
},
|
|
|
|
'VariableDeclaration > VariableDeclarator[init.name="primordials"]'({ id: node }) {
|
|
const { loc } = node;
|
|
if (loc.start.line === loc.end.line) {
|
|
context.report({
|
|
node,
|
|
message: 'destructuring from primordials should be multiline',
|
|
});
|
|
}
|
|
},
|
|
|
|
'VariableDeclaration > VariableDeclarator[init.name="primordials"] Property:not(:first-child)'(node) {
|
|
const { properties } = node.parent;
|
|
const prev = properties[properties.indexOf(node) - 1].key.name;
|
|
const curr = node.key.name;
|
|
if (prev >= curr) {
|
|
const message = [prefix, prev, opStr, curr].join('');
|
|
context.report({ node, message });
|
|
}
|
|
},
|
|
};
|
|
},
|
|
};
|