mirror of
https://github.com/nodejs/node.git
synced 2026-11-21 12:59:16 -05:00
tools: add lint rule to keep primordials in ASCII order
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>
This commit is contained in:
1 parent
461722d64c
commit
a596af0819
96 files changed
+337
-190
No files matched your search
@@ -0,0 +1,57 @@
|
||||
'use strict';
|
||||
|
||||
const common = require('../common');
|
||||
if ((!common.hasCrypto) || (!common.hasIntl)) {
|
||||
common.skip('ESLint tests require crypto and Intl');
|
||||
}
|
||||
|
||||
common.skipIfEslintMissing();
|
||||
|
||||
const RuleTester = require('../../tools/node_modules/eslint').RuleTester;
|
||||
const rule = require('../../tools/eslint-rules/alphabetize-primordials');
|
||||
|
||||
new RuleTester({
|
||||
parserOptions: { ecmaVersion: 6 },
|
||||
env: { es6: true }
|
||||
})
|
||||
.run('alphabetize-primordials', rule, {
|
||||
valid: [
|
||||
'new Array()',
|
||||
'"use strict";const {\nArray\n} = primordials;',
|
||||
'"use strict";const {\n\tArray,\n\tDate,\n} = primordials',
|
||||
'"use strict";const {\nDate,Array\n} = notPrimordials',
|
||||
'"use strict";const {\nDate,globalThis:{Array}\n} = primordials',
|
||||
'"use strict";const {\nBigInt,globalThis:{Array,Date,SharedArrayBuffer,parseInt}\n} = primordials',
|
||||
'"use strict";const {\nFunctionPrototypeBind,Uint32Array,globalThis:{SharedArrayBuffer}\n} = primordials',
|
||||
{
|
||||
code: '"use strict";const fs = require("fs");const {\nArray\n} = primordials',
|
||||
options: [{ enforceTopPosition: false }],
|
||||
},
|
||||
],
|
||||
invalid: [
|
||||
{
|
||||
code: '"use strict";const {Array} = primordials;',
|
||||
errors: [{ message: /destructuring from primordials should be multiline/ }],
|
||||
},
|
||||
{
|
||||
code: '"use strict";const fs = require("fs");const {Date,Array} = primordials',
|
||||
errors: [
|
||||
{ message: /destructuring from primordials should be multiline/ },
|
||||
{ message: /destructuring from primordials should be the first expression/ },
|
||||
{ message: /Date >= Array/ },
|
||||
],
|
||||
},
|
||||
{
|
||||
code: 'function fn() {"use strict";const {\nArray,\n} = primordials}',
|
||||
errors: [{ message: /destructuring from primordials should be the first expression/ }],
|
||||
},
|
||||
{
|
||||
code: '"use strict";const {\nDate,Array} = primordials',
|
||||
errors: [{ message: /Date >= Array/ }],
|
||||
},
|
||||
{
|
||||
code: '"use strict";const {\nglobalThis:{Date, Array}} = primordials',
|
||||
errors: [{ message: /Date >= Array/ }],
|
||||
},
|
||||
]
|
||||
});
|
||||
Reference in new issue
Block a user