Skip to content

Commit

Permalink
Require ESLint 8 (#1724)
Browse files Browse the repository at this point in the history
  • Loading branch information
fisker committed Feb 16, 2022
1 parent f14aa95 commit 608a90c
Show file tree
Hide file tree
Showing 4 changed files with 67 additions and 4 deletions.
2 changes: 1 addition & 1 deletion configs/recommended.js
@@ -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
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-plugin-internal-rules": "file:./scripts/internal-rules/",
Expand All @@ -90,7 +90,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
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
63 changes: 63 additions & 0 deletions test/package.mjs
Expand Up @@ -2,6 +2,7 @@ import fs, {promises as fsAsync} from 'node:fs';
import path from 'node:path';
import test from 'ava';
import {ESLint} from 'eslint';
import * as eslintrc from '@eslint/eslintrc';
import eslintPluginUnicorn from '../index.js';
import {RULE_NOTICE_MARK, getRuleNoticesSectionBody} from '../scripts/rule-notices.mjs';
import {RULES_TABLE_MARK, getRulesTable} from '../scripts/rules-table.mjs';
Expand Down Expand Up @@ -121,6 +122,68 @@ test('validate configuration', async t => {
`Configuration for "${name}" is invalid.`,
);
}

// `env`
{
// https://github.com/eslint/eslint/blob/32ac37a76b2e009a8f106229bc7732671d358189/conf/globals.js#L19
const testObjects = [
'undefinedGlobalObject',
// `es3`
'Array',
// `es5`
'JSON',
// `es2015`(`es6`)
'Promise',
// `es2021`
'WeakRef',
];
const baseOptions = {
useEslintrc: false,
plugins: {
unicorn: eslintPluginUnicorn,
},
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(), ['undefinedGlobalObject', 'Promise', 'WeakRef']);
t.deepEqual(await getUndefinedGlobals({baseConfig: eslintPluginUnicorn.configs.recommended}), ['undefinedGlobalObject']);

const availableEnvironments = [...eslintrc.Legacy.environments.keys()].filter(name => /^es\d+$/.test(name));
const recommendedEnvironments = Object.keys(eslintPluginUnicorn.configs.recommended.env);
t.is(recommendedEnvironments.length, 1);
t.is(
availableEnvironments[availableEnvironments.length - 1],
recommendedEnvironments[0],
'env should be the latest es version',
);
}

// `sourceType`
{
const text = 'import fs from "node:fs";';
const baseOptions = {
useEslintrc: false,
plugins: {
unicorn: eslintPluginUnicorn,
},
};
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: eslintPluginUnicorn.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 608a90c

Please sign in to comment.