mirror of
https://github.com/nodejs/node.git
synced 2024-11-25 08:19:38 +01:00
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 });
|
||
|
}
|
||
|
},
|
||
|
};
|
||
|
},
|
||
|
};
|