Skip to content

Commit

Permalink
fix: Don't override n/no-unsupported-features/* if user has customi…
Browse files Browse the repository at this point in the history
…sed them
  • Loading branch information
melusc committed Jul 20, 2024
1 parent 112e657 commit f6506fe
Show file tree
Hide file tree
Showing 5 changed files with 48 additions and 3 deletions.
6 changes: 3 additions & 3 deletions lib/options-manager.js
Original file line number Diff line number Diff line change
Expand Up @@ -354,9 +354,9 @@ const buildXOConfig = options => config => {
}

if (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}];
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
23 changes: 23 additions & 0 deletions test/cli.js
Original file line number Diff line number Diff line change
Expand Up @@ -197,3 +197,26 @@ test('print-config flag without filename', async t => {
);
t.is(error.stderr.trim(), 'The `--print-config` flag must be used with exactly one filename');
});

test('Disable n/no-unsupported-features/*', async t => {
const cwd = path.join(__dirname, 'fixtures/disable-n-no-unsupported-features');
const {stdout} = await main(['--print-config', 'index.js'], {cwd});
const config = JSON.parse(stdout);
t.like(config, {
rules: {
'n/no-unsupported-features/es-builtins': ['off'],
'n/no-unsupported-features/es-syntax': ['off'],
'n/no-unsupported-features/node-builtins': ['off'],
},
});

const {stdout: stdoutOverrides} = await main(['--print-config', 'overrides.js'], {cwd});
const configOverrides = JSON.parse(stdoutOverrides);
t.like(configOverrides, {
rules: {
'n/no-unsupported-features/es-builtins': ['off'],
'n/no-unsupported-features/es-syntax': ['off'],
'n/no-unsupported-features/node-builtins': ['error'],
},
});
});
1 change: 1 addition & 0 deletions test/fixtures/disable-n-no-unsupported-features/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
const _ = new FormData();
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
const _ = new FormData();
20 changes: 20 additions & 0 deletions test/fixtures/disable-n-no-unsupported-features/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
{
"xo": {
"rules": {
"n/no-unsupported-features/es-builtins": "off",
"n/no-unsupported-features/es-syntax": "off",
"n/no-unsupported-features/node-builtins": "off"
},
"overrides": [
{
"files": "overrides.js",
"rules": {
"n/no-unsupported-features/node-builtins": "error"
}
}
]
},
"engines": {
"node": ">=18"
}
}

0 comments on commit f6506fe

Please sign in to comment.