mirror of
https://github.com/zebrajr/node.git
synced 2025-12-06 12:20:27 +01:00
We've added a number of tests that hook into ESLint which can error when running the test suite with the distributed tarball. This PR adds a new test helper `common.skipIfEslintMissing` and will skip remaining tests in a file when `ESLint` is not available at `tools/node_modules/eslint` PR-URL: https://github.com/nodejs/node/pull/18807 Reviewed-By: Rich Trott <rtrott@gmail.com> Reviewed-By: Richard Lau <riclau@uk.ibm.com> Reviewed-By: James M Snell <jasnell@gmail.com> Reviewed-By: Yuta Hiroto <hello@about-hiroppy.com> Reviewed-By: Colin Ihrig <cjihrig@gmail.com> Reviewed-By: Ruben Bridgewater <ruben@bridgewater.de>
44 lines
1.1 KiB
JavaScript
44 lines
1.1 KiB
JavaScript
'use strict';
|
|
|
|
const common = require('../common');
|
|
|
|
common.skipIfEslintMissing();
|
|
|
|
const RuleTester = require('../../tools/node_modules/eslint').RuleTester;
|
|
const rule = require('../../tools/eslint-rules/no-let-in-for-declaration');
|
|
|
|
const ruleTester = new RuleTester({ parserOptions: { ecmaVersion: 6 } });
|
|
|
|
const message = 'Use of `let` as the loop variable in a for-loop is ' +
|
|
'not recommended. Please use `var` instead.';
|
|
|
|
ruleTester.run('no-let-in-for-declaration', rule, {
|
|
valid: [
|
|
'let foo;',
|
|
'for (var foo = 1;;);',
|
|
'for (foo = 1;;);',
|
|
'for (;;);',
|
|
'for (const foo of bar);',
|
|
'for (var foo of bar);',
|
|
'for (const foo in bar);',
|
|
'for (var foo in bar);'
|
|
],
|
|
invalid: [
|
|
{
|
|
code: 'for (let foo = 1;;);',
|
|
output: 'for (var foo = 1;;);',
|
|
errors: [{ message }]
|
|
},
|
|
{
|
|
code: 'for (let foo in bar);',
|
|
output: 'for (var foo in bar);',
|
|
errors: [{ message }]
|
|
},
|
|
{
|
|
code: 'for (let foo of bar);',
|
|
output: 'for (var foo of bar);',
|
|
errors: [{ message }]
|
|
}
|
|
]
|
|
});
|