Skip to content

Commit

Permalink
Remove the esnext option
Browse files Browse the repository at this point in the history
  • Loading branch information
sindresorhus committed Apr 14, 2021
1 parent b385bee commit e80c094
Show file tree
Hide file tree
Showing 19 changed files with 44 additions and 93 deletions.
4 changes: 0 additions & 4 deletions cli-main.js
Expand Up @@ -27,7 +27,6 @@ const cli = meow(`
--open Open files with issues in your editor
--quiet Show only errors and no warnings
--extension Additional extension to lint [Can be set multiple times]
--no-esnext Don't enforce ES2015+ rules
--cwd=<dir> Working directory for files
--stdin Validate/fix code from stdin
--stdin-filename Specify a filename for the --stdin option
Expand Down Expand Up @@ -97,9 +96,6 @@ const cli = meow(`
type: 'string',
isMultiple: true
},
esnext: {
type: 'boolean'
},
cwd: {
type: 'string'
},
Expand Down
19 changes: 7 additions & 12 deletions lib/options-manager.js
Expand Up @@ -162,9 +162,11 @@ const mergeWithFileConfigs = async (files, options, configFiles) => {
([tsConfigPath, groups]) => {
const files = [].concat(...groups.map(group => group.files));
const cachePath = getTsConfigCachePath(files, tsConfigPath);
groups.forEach(group => {

for (const group of groups) {
group.options.tsConfigPath = cachePath;
});
}

return outputJson(cachePath, makeTSConfig(tsConfigs[tsConfigPath], tsConfigPath, files));
}
));
Expand All @@ -180,11 +182,11 @@ Hashing based on https://github.com/eslint/eslint/blob/cf38d0d939b62f3670cdd59f0
*/
const getTsConfigCachePath = (files, tsConfigPath) => path.join(
cacheLocation,
`tsconfig.${murmur(`${pkg.version}_${nodeVersion}_${stringify({files: files.sort(), tsConfigPath: tsConfigPath})}`).result().toString(36)}.json`
`tsconfig.${murmur(`${pkg.version}_${nodeVersion}_${stringify({files: files.sort(), tsConfigPath})}`).result().toString(36)}.json`
);

const makeTSConfig = (tsConfig, tsConfigPath, files) => {
const config = {files: files.filter(isTypescript)};
const config = {files: files.filter(file => isTypescript(file))};

if (tsConfig) {
config.extends = tsConfigPath;
Expand Down Expand Up @@ -308,13 +310,6 @@ const buildXOConfig = options => config => {
}];
}

if (options.esnext !== false) {
config.baseConfig.extends = [
'xo/esnext',
path.join(__dirname, '../config/plugins.js')
];
}

if (options.ts) {
config.rules['unicorn/import-style'] = 'off';
config.rules['node/file-extension-in-import'] = 'off';
Expand Down Expand Up @@ -464,7 +459,7 @@ const applyOverrides = (file, options) => {
const {overrides} = options;
delete options.overrides;

let {applicable, hash} = findApplicableOverrides(path.relative(options.cwd, file), overrides);
const {applicable, hash} = findApplicableOverrides(path.relative(options.cwd, file), overrides);

options = mergeWith(...[getEmptyOptions(), options].concat(applicable.map(override => normalizeOptions(override)), mergeFn));
delete options.files;
Expand Down
2 changes: 1 addition & 1 deletion package.json
Expand Up @@ -58,7 +58,7 @@
"debug": "^4.3.1",
"eslint": "^7.20.0",
"eslint-config-prettier": "^7.2.0",
"eslint-config-xo": "^0.35.0",
"eslint-config-xo": "^0.36.0",
"eslint-config-xo-typescript": "^0.38.0",
"eslint-formatter-pretty": "^4.0.0",
"eslint-import-resolver-webpack": "^0.13.0",
Expand Down
19 changes: 3 additions & 16 deletions readme.md
Expand Up @@ -68,7 +68,6 @@ $ xo --help
--open Open files with issues in your editor
--quiet Show only errors and no warnings
--extension Additional extension to lint [Can be set multiple times]
--no-esnext Don't enforce ES2015+ rules
--cwd=<dir> Working directory for files
--stdin Validate/fix code from stdin
--stdin-filename Specify a filename for the --stdin option
Expand Down Expand Up @@ -267,15 +266,6 @@ Type: `string`

[ESLint processor.](https://eslint.org/docs/user-guide/configuring#specifying-processor)

### esnext

Type: `boolean`\
Default: `true`

Enforce ES2015+ rules. Disabling this will make it not *enforce* ES2015+ syntax and conventions.

*ES2015+ is parsed even without this option. You can already use ES2017 features like [`async`/`await`](https://github.com/lukehoban/ecmascript-asyncawait).

### webpack

Type: `boolean | object`
Expand Down Expand Up @@ -317,12 +307,11 @@ XO makes it easy to override configs for specific files. The `overrides` propert
"overrides": [
{
"files": "test/*.js",
"esnext": false,
"space": 3
},
{
"files": "test/foo.js",
"esnext": true
"semicolon": true
}
]
}
Expand All @@ -331,11 +320,10 @@ XO makes it easy to override configs for specific files. The `overrides` propert

- The base configuration is simply `space: 2`, `semicolon: false`. These settings are used for every file unless otherwise noted below.

- For every file in `test/*.js`, the base config is used, but `space` is overridden with `3`, and the `esnext` option is set to `false`. The resulting config is:
- For every file in `test/*.js`, the base config is used, but `space` is overridden with `3`. The resulting config is:

```json
{
"esnext": false,
"semicolon": false,
"space": 3
}
Expand All @@ -345,8 +333,7 @@ XO makes it easy to override configs for specific files. The `overrides` propert

```json
{
"esnext": true,
"semicolon": false,
"semicolon": true,
"space": 3
}
```
Expand Down
2 changes: 1 addition & 1 deletion test/fixtures/config-files/xo-config/.xo-config
@@ -1,3 +1,3 @@
{
"esnext": true
"space": true
}
7 changes: 5 additions & 2 deletions test/fixtures/config-files/xo-config/file.js
@@ -1,2 +1,5 @@
var obj = { a: 1 };
console.log(obj.a);
const object = {
a: 1
};

console.log(object.a);
4 changes: 2 additions & 2 deletions test/fixtures/config-files/xo-config_js/.xo-config.js
@@ -1,3 +1,3 @@
module.exports = {
esnext: true
}
space: true
};
7 changes: 5 additions & 2 deletions test/fixtures/config-files/xo-config_js/file.js
@@ -1,2 +1,5 @@
var obj = { a: 1 };
console.log(obj.a);
const object = {
a: 1
};

console.log(object.a);
2 changes: 1 addition & 1 deletion test/fixtures/config-files/xo-config_json/.xo-config.json
@@ -1,3 +1,3 @@
{
"esnext": true
"space": true
}
7 changes: 5 additions & 2 deletions test/fixtures/config-files/xo-config_json/file.js
@@ -1,2 +1,5 @@
var obj = { a: 1 };
console.log(obj.a);
const object = {
a: 1
};

console.log(object.a);
7 changes: 5 additions & 2 deletions test/fixtures/config-files/xo_config_js/file.js
@@ -1,2 +1,5 @@
var obj = { a: 1 };
console.log(obj.a);
const object = {
a: 1
};

console.log(object.a);
4 changes: 2 additions & 2 deletions test/fixtures/config-files/xo_config_js/xo.config.js
@@ -1,3 +1,3 @@
module.exports = {
esnext: true
}
space: true
};
2 changes: 1 addition & 1 deletion test/fixtures/nested/child/package.json
@@ -1,5 +1,5 @@
{
"xo": {
"esnext": false
"space": true
}
}
4 changes: 2 additions & 2 deletions test/fixtures/nested/file.js
@@ -1,2 +1,2 @@
var obj = { a: 1 };
console.log(obj.a);
const object = {a: 1};
console.log(object.a);
2 changes: 1 addition & 1 deletion test/fixtures/nested/package.json
@@ -1,5 +1,5 @@
{
"xo": {
"esnext": true
"space": true
}
}
1 change: 0 additions & 1 deletion test/fixtures/overrides/package.json
Expand Up @@ -5,7 +5,6 @@
"overrides": [
{
"files": "test/*.js",
"esnext": true,
"space": 3
},
{
Expand Down
6 changes: 3 additions & 3 deletions test/lint-files.js
Expand Up @@ -197,8 +197,8 @@ test('typescript files', async t => {
});

test('typescript 2 space option', async t => {
const {errorCount} = await fn.lintFiles('two-spaces.tsx', {cwd: 'fixtures/typescript', space: 2});
t.is(errorCount, 0);
const {errorCount, results} = await fn.lintFiles('two-spaces.tsx', {cwd: 'fixtures/typescript', space: 2});
t.is(errorCount, 0, JSON.stringify(results[0].messages));
});

test('typescript 4 space option', async t => {
Expand Down Expand Up @@ -270,7 +270,7 @@ async function configType(t, {dir}) {
hasRule(
results,
path.resolve('fixtures', 'config-files', dir, 'file.js'),
'no-var'
'indent'
)
);
}
Expand Down
12 changes: 0 additions & 12 deletions test/lint-text.js
Expand Up @@ -102,13 +102,6 @@ test('extends support', t => {
t.true(hasRule(results, 'react/jsx-no-undef'));
});

test('extends support with `esnext` option', t => {
const {results} = fn.lintText('import path from \'path\';\nlet React;\nReact.render(<App/>);\n', {
extends: 'xo-react'
});
t.true(hasRule(results, 'react/jsx-no-undef'));
});

test('disable style rules when `prettier` option is enabled', t => {
const withoutPrettier = fn.lintText('(a) => {}\n', {filename: 'test.js'}).results;
// `arrow-parens` is enabled
Expand All @@ -131,11 +124,6 @@ test('extends `react` support with `prettier` option', t => {
t.true(hasRule(results, 'prettier/prettier'));
});

test('always use the latest ECMAScript parser so esnext syntax won\'t throw in normal mode', t => {
const {results} = fn.lintText('async function foo() {}\n\nfoo();\n');
t.is(results[0].errorCount, 0);
});

test('regression test for #71', t => {
const {results} = fn.lintText('const foo = { key: \'value\' };\nconsole.log(foo);\n', {
extends: path.join(__dirname, 'fixtures/extends.js')
Expand Down
26 changes: 0 additions & 26 deletions test/options-manager.js
Expand Up @@ -49,11 +49,6 @@ test('buildConfig: defaults', t => {
t.regex(slash(config.cacheLocation), /[\\/]\.cache\/xo-linter\/xo-cache.json[\\/]?$/u);
t.is(config.useEslintrc, false);
t.is(config.cache, true);
t.is(config.baseConfig.extends[0], 'xo/esnext');
});

test('buildConfig: esnext', t => {
const config = manager.buildConfig({esnext: false});
t.is(config.baseConfig.extends[0], 'xo');
});

Expand Down Expand Up @@ -171,27 +166,6 @@ test('buildConfig: prettier: true, space: 4', t => {
t.is(config.rules['semi-spacing'], undefined);
});

test('buildConfig: prettier: true, esnext: false', t => {
const config = manager.buildConfig({prettier: true, esnext: false}, {});

// Sets `useTabs` and `tabWidth` options in `prettier/prettier` rule based on the XO `space` options
t.deepEqual(config.rules['prettier/prettier'], ['error', {
useTabs: true,
bracketSpacing: false,
jsxBracketSameLine: false,
semi: true,
singleQuote: true,
tabWidth: 2,
trailingComma: 'none'
}]);
// Indent rule is not enabled
t.is(config.rules.indent, undefined);
// Semi rule is not enabled
t.is(config.rules.semi, undefined);
// Semi-spacing is not enabled
t.is(config.rules['semi-spacing'], undefined);
});

test('buildConfig: prettier: true, space: true', t => {
const config = manager.buildConfig({prettier: true, space: true}, {});

Expand Down

0 comments on commit e80c094

Please sign in to comment.