Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat!: switch to eslint-plugin-node's maintained fork #660

Merged
merged 3 commits into from
May 27, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
48 changes: 24 additions & 24 deletions config/plugins.cjs
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ module.exports = {
// Disabled as the plugin doesn't support ESLint 8 yet.
// 'promise',
'import',
'node',
'n', // eslint-plugin-node's successor
'eslint-comments',
],
extends: [
Expand Down Expand Up @@ -264,17 +264,17 @@ module.exports = {
],

// Redundant with `import/no-extraneous-dependencies`.
// 'node/no-extraneous-import': 'error',
// 'node/no-extraneous-require': 'error',
// 'n/no-extraneous-import': 'error',
// 'n/no-extraneous-require': 'error',

// Redundant with `import/no-unresolved`.
// 'node/no-missing-import': 'error', // This rule is also buggy and doesn't support `node:`.
// 'node/no-missing-require': 'error',
// 'n/no-missing-import': 'error', // This rule is also buggy and doesn't support `node:`.
// 'n/no-missing-require': 'error',

'node/no-unpublished-bin': 'error',
'n/no-unpublished-bin': 'error',

// We have this enabled in addition to `import/extensions` as this one has an auto-fix.
'node/file-extension-in-import': [
'n/file-extension-in-import': [
'error',
'always',
{
Expand All @@ -283,19 +283,19 @@ module.exports = {
'.tsx': 'never',
},
],
'node/no-mixed-requires': [
'n/no-mixed-requires': [
'error',
{
grouping: true,
allowCall: true,
},
],
'node/no-new-require': 'error',
'node/no-path-concat': 'error',
'n/no-new-require': 'error',
'n/no-path-concat': 'error',

// Disabled because they're too annoying, see:
// https://github.com/mysticatea/eslint-plugin-node/issues/105
// 'node/no-unpublished-import': [
// 'n/no-unpublished-import': [
// 'error',
// {
// allowModules: [
Expand All @@ -304,7 +304,7 @@ module.exports = {
// ]
// }
// ],
// 'node/no-unpublished-require': [
// 'n/no-unpublished-require': [
// 'error',
// {
// allowModules: [
Expand All @@ -314,42 +314,42 @@ module.exports = {
// }
// ],

'node/process-exit-as-throw': 'error',
'n/process-exit-as-throw': 'error',

// Disabled as the rule doesn't exclude scripts executed with `node` but not referenced in 'bin'. See https://github.com/mysticatea/eslint-plugin-node/issues/96
// 'node/shebang': 'error',
// 'n/shebang': 'error',

'node/no-deprecated-api': 'error',
'node/prefer-global/buffer': [
'n/no-deprecated-api': 'error',
'n/prefer-global/buffer': [
'error',
'never',
],
'node/prefer-global/console': [
'n/prefer-global/console': [
'error',
'always',
],
'node/prefer-global/process': [
'n/prefer-global/process': [
'error',
'never',
],
'node/prefer-global/text-decoder': [
'n/prefer-global/text-decoder': [
'error',
'always',
],
'node/prefer-global/text-encoder': [
'n/prefer-global/text-encoder': [
'error',
'always',
],
'node/prefer-global/url-search-params': [
'n/prefer-global/url-search-params': [
'error',
'always',
],
'node/prefer-global/url': [
'n/prefer-global/url': [
'error',
'always',
],
'node/prefer-promises/dns': 'error',
'node/prefer-promises/fs': 'error',
'n/prefer-promises/dns': 'error',
'n/prefer-promises/fs': 'error',
'eslint-comments/disable-enable-pair': [
'error',
{
Expand Down
12 changes: 6 additions & 6 deletions lib/constants.js
Original file line number Diff line number Diff line change
Expand Up @@ -77,10 +77,10 @@ const ENGINE_RULES = {
'prefer-object-spread': {
'8.3.0': 'off',
},
'node/prefer-global/url-search-params': {
'n/prefer-global/url-search-params': {
'10.0.0': 'off',
},
'node/prefer-global/url': {
'n/prefer-global/url': {
'10.0.0': 'off',
},
'no-useless-catch': {
Expand All @@ -89,19 +89,19 @@ const ENGINE_RULES = {
'prefer-named-capture-group': {
'10.0.0': 'off',
},
'node/prefer-global/text-encoder': {
'n/prefer-global/text-encoder': {
'11.0.0': 'off',
},
'node/prefer-global/text-decoder': {
'n/prefer-global/text-decoder': {
'11.0.0': 'off',
},
'unicorn/prefer-flat-map': {
'11.0.0': 'off',
},
'node/prefer-promises/dns': {
'n/prefer-promises/dns': {
'11.14.0': 'off',
},
'node/prefer-promises/fs': {
'n/prefer-promises/fs': {
'11.14.0': 'off',
},
};
Expand Down
6 changes: 3 additions & 3 deletions lib/options-manager.js
Original file line number Diff line number Diff line change
Expand Up @@ -327,9 +327,9 @@ const buildXOConfig = options => config => {
}

if (options.nodeVersion) {
config.baseConfig.rules['node/no-unsupported-features/es-builtins'] = ['error', {version: options.nodeVersion}];
config.baseConfig.rules['node/no-unsupported-features/es-syntax'] = ['error', {version: options.nodeVersion, ignores: ['modules']}];
config.baseConfig.rules['node/no-unsupported-features/node-builtins'] = ['error', {version: options.nodeVersion}];
config.baseConfig.rules['n/no-unsupported-features/es-builtins'] = ['error', {version: options.nodeVersion}];
config.baseConfig.rules['n/no-unsupported-features/es-syntax'] = ['error', {version: options.nodeVersion, ignores: ['modules']}];
config.baseConfig.rules['n/no-unsupported-features/node-builtins'] = ['error', {version: options.nodeVersion}];
}

if (options.space && !options.prettier) {
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -73,8 +73,8 @@
"eslint-plugin-ava": "^13.2.0",
"eslint-plugin-eslint-comments": "^3.2.0",
"eslint-plugin-import": "^2.26.0",
"eslint-plugin-n": "^15.1.0",
"eslint-plugin-no-use-extend-native": "^0.5.0",
"eslint-plugin-node": "^11.1.0",
"eslint-plugin-prettier": "^4.0.0",
"eslint-plugin-unicorn": "^42.0.0",
"esm-utils": "^4.0.0",
Expand Down
30 changes: 15 additions & 15 deletions test/options-manager.js
Original file line number Diff line number Diff line change
Expand Up @@ -222,11 +222,11 @@ test('buildConfig: engines: undefined', t => {
t.is(config.baseConfig.rules['prefer-destructuring'], 'off');
t.is(config.baseConfig.rules['promise/prefer-await-to-then'], 'off');
t.is(config.baseConfig.rules['unicorn/prefer-flat-map'], 'off');
t.is(config.baseConfig.rules['node/prefer-promises/dns'], 'off');
t.is(config.baseConfig.rules['node/prefer-promises/fs'], 'off');
t.is(config.baseConfig.rules['node/no-unsupported-features/es-builtins'], undefined);
t.is(config.baseConfig.rules['node/no-unsupported-features/es-syntax'], undefined);
t.is(config.baseConfig.rules['node/no-unsupported-features/node-builtins'], undefined);
t.is(config.baseConfig.rules['n/prefer-promises/dns'], 'off');
t.is(config.baseConfig.rules['n/prefer-promises/fs'], 'off');
t.is(config.baseConfig.rules['n/no-unsupported-features/es-builtins'], undefined);
t.is(config.baseConfig.rules['n/no-unsupported-features/es-syntax'], undefined);
t.is(config.baseConfig.rules['n/no-unsupported-features/node-builtins'], undefined);
});

test('buildConfig: nodeVersion: false', t => {
Expand All @@ -238,36 +238,36 @@ test('buildConfig: nodeVersion: false', t => {
t.is(config.baseConfig.rules['prefer-destructuring'], 'off');
t.is(config.baseConfig.rules['promise/prefer-await-to-then'], 'off');
t.is(config.baseConfig.rules['unicorn/prefer-flat-map'], 'off');
t.is(config.baseConfig.rules['node/prefer-promises/dns'], 'off');
t.is(config.baseConfig.rules['node/prefer-promises/fs'], 'off');
t.is(config.baseConfig.rules['n/prefer-promises/dns'], 'off');
t.is(config.baseConfig.rules['n/prefer-promises/fs'], 'off');
});

test('buildConfig: nodeVersion: >=6', t => {
const config = manager.buildConfig({nodeVersion: '>=6'});

// Turn off rule if we support Node.js below 7.6.0
t.is(config.baseConfig.rules['promise/prefer-await-to-then'], 'off');
// Set node/no-unsupported-features rules with the nodeVersion
t.deepEqual(config.baseConfig.rules['node/no-unsupported-features/es-builtins'], ['error', {version: '>=6'}]);
// Set n/no-unsupported-features rules with the nodeVersion
t.deepEqual(config.baseConfig.rules['n/no-unsupported-features/es-builtins'], ['error', {version: '>=6'}]);
t.deepEqual(
config.baseConfig.rules['node/no-unsupported-features/es-syntax'],
config.baseConfig.rules['n/no-unsupported-features/es-syntax'],
['error', {version: '>=6', ignores: ['modules']}],
);
t.deepEqual(config.baseConfig.rules['node/no-unsupported-features/node-builtins'], ['error', {version: '>=6'}]);
t.deepEqual(config.baseConfig.rules['n/no-unsupported-features/node-builtins'], ['error', {version: '>=6'}]);
});

test('buildConfig: nodeVersion: >=8', t => {
const config = manager.buildConfig({nodeVersion: '>=8'});

// Do not turn off rule if we support only Node.js above 7.6.0
t.is(config.baseConfig.rules['promise/prefer-await-to-then'], undefined);
// Set node/no-unsupported-features rules with the nodeVersion
t.deepEqual(config.baseConfig.rules['node/no-unsupported-features/es-builtins'], ['error', {version: '>=8'}]);
// Set n/no-unsupported-features rules with the nodeVersion
t.deepEqual(config.baseConfig.rules['n/no-unsupported-features/es-builtins'], ['error', {version: '>=8'}]);
t.deepEqual(
config.baseConfig.rules['node/no-unsupported-features/es-syntax'],
config.baseConfig.rules['n/no-unsupported-features/es-syntax'],
['error', {version: '>=8', ignores: ['modules']}],
);
t.deepEqual(config.baseConfig.rules['node/no-unsupported-features/node-builtins'], ['error', {version: '>=8'}]);
t.deepEqual(config.baseConfig.rules['n/no-unsupported-features/node-builtins'], ['error', {version: '>=8'}]);
});

test('mergeWithPrettierConfig: use `singleQuote`, `trailingComma`, `bracketSpacing` and `bracketSameLine` from `prettier` config if defined', t => {
Expand Down