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

Require ESLint 8 #1724

Merged
merged 4 commits into from
Feb 16, 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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 1 addition & 1 deletion configs/recommended.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
63 changes: 63 additions & 0 deletions test/package.mjs
Original file line number Diff line number Diff line change
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