Skip to content

Commit

Permalink
Update env config
Browse files Browse the repository at this point in the history
  • Loading branch information
fisker committed Feb 9, 2022
1 parent ba9d53c commit ce9fc15
Show file tree
Hide file tree
Showing 4 changed files with 52 additions and 4 deletions.
2 changes: 1 addition & 1 deletion configs/base.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
'use strict';
module.exports = {
env: {
es6: true,
es2021: true,
},
parserOptions: {
ecmaVersion: 'latest',
Expand Down
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@
"c8": "^7.11.0",
"chalk": "^5.0.0",
"enquirer": "^2.3.6",
"eslint": "^8.6.0",
"eslint": "^8.8.0",
"eslint-ava-rule-tester": "^4.0.0",
"eslint-plugin-eslint-plugin": "^4.1.0",
"eslint-remote-tester": "^2.0.1",
Expand All @@ -89,7 +89,7 @@
"xo": "^0.47.0"
},
"peerDependencies": {
"eslint": ">=7.32.0"
"eslint": ">=8.8.0"
},
"ava": {
"files": [
Expand Down
2 changes: 1 addition & 1 deletion readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ Use a [preset config](#preset-configs) or configure each rules in `package.json`
"name": "my-awesome-project",
"eslintConfig": {
"env": {
"es6": true
"es2021": true
},
"parserOptions": {
"ecmaVersion": "latest",
Expand Down
48 changes: 48 additions & 0 deletions test/package.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,54 @@ test('validate configuration', async t => {
}

await Promise.all(results);

// `env`
{
const testObjects = [
'undefinedGlobalObject',
// `es2015`(`es6`) globals https://github.com/eslint/eslint/blob/32ac37a76b2e009a8f106229bc7732671d358189/conf/globals.js#L74
'Promise',
// `es2021` globals https://github.com/eslint/eslint/blob/32ac37a76b2e009a8f106229bc7732671d358189/conf/globals.js#L120
'WeakRef',
];
const baseOptions = {
useEslintrc: false,
plugins: {
unicorn: index,
},
overrideConfig: {
rules: {
'no-undef': 'error',
},
},
};
const getUndefinedGlobals = async options => {
const [{messages}] = await new ESLint({...baseOptions, ...options}).lintText(testObjects.join(';\n'));
return messages.map(({message}) => message.match(/^'(?<object>.*)' is not defined\.$/).groups.object);
};

t.deepEqual(await getUndefinedGlobals(), testObjects);
t.deepEqual(await getUndefinedGlobals({baseConfig: index.configs.recommended}), testObjects.slice(0, 1));
}

// `sourceType`
{
const text = 'import fs from "node:fs";';
const baseOptions = {
useEslintrc: false,
plugins: {
unicorn: index,
},
};
const runEslint = async options => {
const [{messages}] = await new ESLint({...baseOptions, ...options}).lintText(text);
return messages;
};

const [{message}] = await runEslint();
t.is(message, 'Parsing error: The keyword \'import\' is reserved');
t.deepEqual(await runEslint({baseConfig: index.configs.recommended}), []);
}
});

test('Every rule is defined in readme.md usage and list of rules in alphabetical order', async t => {
Expand Down

0 comments on commit ce9fc15

Please sign in to comment.