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

ci: run against upcoming next major ESLint version #1534

Merged
merged 16 commits into from
Mar 31, 2024
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.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .eslintrc.js
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ module.exports = {
globals,
},
{
files: ['src/**/*', 'dangerfile.ts', 'tools/*'],
files: ['src/**/*', 'dangerfile.ts', 'tools/*', './jest.config.ts'],
parserOptions: {
sourceType: 'module',
},
Expand Down
7 changes: 5 additions & 2 deletions .github/workflows/nodejs.yml
Original file line number Diff line number Diff line change
Expand Up @@ -72,12 +72,15 @@ jobs:
fail-fast: false
matrix:
node-version: [16.x, 18.x, 19.x, 20.x, 21.x]
eslint-version: [7, 8]
eslint-version: [7, 8, next]
ts-eslint-plugin-version: [6, 7]
exclude:
# ts-eslint/plugin@7 doesn't support node@16
- node-version: 16.x
ts-eslint-plugin-version: 7
# eslint@9 doesn't support node@16
- node-version: 16.x
eslint-version: next
# ts-eslint/plugin@7 doesn't support node@19
- node-version: 19.x
ts-eslint-plugin-version: 7
Expand All @@ -103,7 +106,7 @@ jobs:
yarn add --dev eslint@${{ matrix.eslint-version }} @typescript-eslint/eslint-plugin@${{ matrix.ts-eslint-plugin-version }} @typescript-eslint/parser@${{ matrix.ts-eslint-plugin-version }}
- name: run tests
# only collect coverage on eslint versions that support dynamic import
run: yarn test --coverage ${{ matrix.eslint-version >= 8 }}
run: yarn test --coverage ${{ matrix.eslint-version == 8 }}
env:
CI: true
- uses: codecov/codecov-action@v3
Expand Down
58 changes: 58 additions & 0 deletions jest.config.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
import { version as typescriptESLintPluginVersion } from '@typescript-eslint/eslint-plugin/package.json';
import { version as eslintVersion } from 'eslint/package.json';
import type { Config } from 'jest';
import * as semver from 'semver';

const config = {
clearMocks: true,
restoreMocks: true,
resetMocks: true,

coverageThreshold: {
global: {
branches: 100,
functions: 100,
lines: 100,
statements: 100,
},
},

projects: [
{
displayName: 'test',
testPathIgnorePatterns: [
'<rootDir>/lib/.*',
'<rootDir>/src/rules/__tests__/fixtures/*',
'<rootDir>/src/rules/__tests__/test-utils.ts',
],
coveragePathIgnorePatterns: ['/node_modules/'],
},
{
displayName: 'lint',
runner: 'jest-runner-eslint',
testMatch: ['<rootDir>/**/*.{js,ts}'],
testPathIgnorePatterns: ['<rootDir>/lib/.*'],
coveragePathIgnorePatterns: ['/node_modules/'],
},
],
} satisfies Config;

if (semver.major(eslintVersion) >= 9) {
config.projects = config.projects.filter(
({ displayName }) => displayName !== 'lint',
);

// jest/unbound-method doesn't work when using @typescript-eslint v6
if (semver.major(typescriptESLintPluginVersion) === 6) {
for (const project of config.projects) {
project.testPathIgnorePatterns.push(
'<rootDir>/src/rules/__tests__/unbound-method.test.ts',
);
project.coveragePathIgnorePatterns.push(
'<rootDir>/src/rules/unbound-method.ts',
);
}
}
}

export default config;
30 changes: 0 additions & 30 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -64,36 +64,6 @@
"@semantic-release/github"
]
},
"jest": {
"coverageThreshold": {
"global": {
"branches": 100,
"functions": 100,
"lines": 100,
"statements": 100
}
},
"projects": [
{
"displayName": "test",
"testPathIgnorePatterns": [
"<rootDir>/lib/.*",
"<rootDir>/src/rules/__tests__/fixtures/*",
"<rootDir>/src/rules/__tests__/test-utils.ts"
]
},
{
"displayName": "lint",
"runner": "jest-runner-eslint",
"testMatch": [
"<rootDir>/**/*.{js,ts}"
],
"testPathIgnorePatterns": [
"<rootDir>/lib/.*"
]
}
]
},
"dependencies": {
"@typescript-eslint/utils": "^6.0.0"
},
Expand Down
5 changes: 2 additions & 3 deletions src/rules/__tests__/consistent-test-it.test.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,9 @@
import { TSESLint } from '@typescript-eslint/utils';
import dedent from 'dedent';
import rule from '../consistent-test-it';
import { TestCaseName } from '../utils';
import { espreeParser } from './test-utils';
import { FlatCompatRuleTester, espreeParser } from './test-utils';

const ruleTester = new TSESLint.RuleTester({
const ruleTester = new FlatCompatRuleTester({
parser: espreeParser,
parserOptions: {
ecmaVersion: 2015,
Expand Down
6 changes: 3 additions & 3 deletions src/rules/__tests__/expect-expect.test.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import { AST_NODE_TYPES, TSESLint } from '@typescript-eslint/utils';
import { AST_NODE_TYPES } from '@typescript-eslint/utils';
import dedent from 'dedent';
import rule from '../expect-expect';
import { espreeParser } from './test-utils';
import { FlatCompatRuleTester, espreeParser } from './test-utils';

const ruleTester = new TSESLint.RuleTester({
const ruleTester = new FlatCompatRuleTester({
parser: espreeParser,
parserOptions: {
ecmaVersion: 2015,
Expand Down
5 changes: 2 additions & 3 deletions src/rules/__tests__/max-expects.test.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
import { TSESLint } from '@typescript-eslint/utils';
import dedent from 'dedent';
import rule from '../max-expects';
import { espreeParser } from './test-utils';
import { FlatCompatRuleTester, espreeParser } from './test-utils';

const ruleTester = new TSESLint.RuleTester({
const ruleTester = new FlatCompatRuleTester({
parser: espreeParser,
parserOptions: {
ecmaVersion: 2017,
Expand Down
5 changes: 2 additions & 3 deletions src/rules/__tests__/max-nested-describe.test.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
import { TSESLint } from '@typescript-eslint/utils';
import dedent from 'dedent';
import rule from '../max-nested-describe';
import { espreeParser } from './test-utils';
import { FlatCompatRuleTester, espreeParser } from './test-utils';

const ruleTester = new TSESLint.RuleTester({
const ruleTester = new FlatCompatRuleTester({
parser: espreeParser,
parserOptions: {
ecmaVersion: 2017,
Expand Down
4 changes: 2 additions & 2 deletions src/rules/__tests__/no-alias-methods.test.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { TSESLint } from '@typescript-eslint/utils';
import rule from '../no-alias-methods';
import { FlatCompatRuleTester } from './test-utils';

const ruleTester = new TSESLint.RuleTester();
const ruleTester = new FlatCompatRuleTester();

ruleTester.run('no-alias-methods', rule, {
valid: [
Expand Down
5 changes: 2 additions & 3 deletions src/rules/__tests__/no-commented-out-tests.test.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
import { TSESLint } from '@typescript-eslint/utils';
import dedent from 'dedent';
import rule from '../no-commented-out-tests';
import { espreeParser } from './test-utils';
import { FlatCompatRuleTester, espreeParser } from './test-utils';

const ruleTester = new TSESLint.RuleTester({
const ruleTester = new FlatCompatRuleTester({
parser: espreeParser,
parserOptions: {
ecmaVersion: 2015,
Expand Down
5 changes: 2 additions & 3 deletions src/rules/__tests__/no-conditional-expect.test.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
import { TSESLint } from '@typescript-eslint/utils';
import dedent from 'dedent';
import rule from '../no-conditional-expect';
import { espreeParser } from './test-utils';
import { FlatCompatRuleTester, espreeParser } from './test-utils';

const ruleTester = new TSESLint.RuleTester({
const ruleTester = new FlatCompatRuleTester({
parser: espreeParser,
parserOptions: {
ecmaVersion: 2019,
Expand Down
5 changes: 2 additions & 3 deletions src/rules/__tests__/no-conditional-in-test.test.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
import { TSESLint } from '@typescript-eslint/utils';
import dedent from 'dedent';
import rule from '../no-conditional-in-test';
import { espreeParser } from './test-utils';
import { FlatCompatRuleTester, espreeParser } from './test-utils';

const ruleTester = new TSESLint.RuleTester({
const ruleTester = new FlatCompatRuleTester({
parser: espreeParser,
parserOptions: {
ecmaVersion: 2015,
Expand Down
5 changes: 2 additions & 3 deletions src/rules/__tests__/no-confusing-set-timeout.test.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
import { TSESLint } from '@typescript-eslint/utils';
import dedent from 'dedent';
import rule from '../no-confusing-set-timeout';
import { espreeParser } from './test-utils';
import { FlatCompatRuleTester, espreeParser } from './test-utils';

const ruleTester = new TSESLint.RuleTester({
const ruleTester = new FlatCompatRuleTester({
parser: espreeParser,
parserOptions: {
ecmaVersion: 2020,
Expand Down
17 changes: 16 additions & 1 deletion src/rules/__tests__/no-deprecated-functions.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,15 @@ import {
type JestVersion,
detectJestVersion,
} from '../utils/detectJestVersion';
import { FlatCompatRuleTester, usingFlatConfig } from './test-utils';

jest.mock('../utils/detectJestVersion');

const detectJestVersionMock = detectJestVersion as jest.MockedFunction<
typeof detectJestVersion
>;

const ruleTester = new TSESLint.RuleTester();
const ruleTester = new FlatCompatRuleTester();

const generateValidCases = (
jestVersion: JestVersion | string | undefined,
Expand Down Expand Up @@ -154,6 +155,20 @@ describe('the rule', () => {
expect(() => {
const linter = new TSESLint.Linter();

/* istanbul ignore if */
if (usingFlatConfig) {
linter.verify('jest.resetModuleRegistry()', [
{
plugins: {
jest: { rules: { 'no-deprecated-functions': rule } },
},
rules: { 'jest/no-deprecated-functions': 'error' },
},
]);

return;
}

linter.defineRule('no-deprecated-functions', rule);

linter.verify('jest.resetModuleRegistry()', {
Expand Down
5 changes: 2 additions & 3 deletions src/rules/__tests__/no-disabled-tests.test.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
import { TSESLint } from '@typescript-eslint/utils';
import dedent from 'dedent';
import rule from '../no-disabled-tests';
import { espreeParser } from './test-utils';
import { FlatCompatRuleTester, espreeParser } from './test-utils';

const ruleTester = new TSESLint.RuleTester({
const ruleTester = new FlatCompatRuleTester({
parser: espreeParser,
parserOptions: {
ecmaVersion: 2015,
Expand Down
5 changes: 2 additions & 3 deletions src/rules/__tests__/no-done-callback.test.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
import { TSESLint } from '@typescript-eslint/utils';
import dedent from 'dedent';
import rule from '../no-done-callback';
import { espreeParser } from './test-utils';
import { FlatCompatRuleTester, espreeParser } from './test-utils';

const ruleTester = new TSESLint.RuleTester({
const ruleTester = new FlatCompatRuleTester({
parser: espreeParser,
parserOptions: {
ecmaVersion: 2017,
Expand Down
5 changes: 2 additions & 3 deletions src/rules/__tests__/no-duplicate-hooks.test.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
import { TSESLint } from '@typescript-eslint/utils';
import dedent from 'dedent';
import rule from '../no-duplicate-hooks';
import { espreeParser } from './test-utils';
import { FlatCompatRuleTester, espreeParser } from './test-utils';

const ruleTester = new TSESLint.RuleTester({
const ruleTester = new FlatCompatRuleTester({
parser: espreeParser,
parserOptions: {
ecmaVersion: 2015,
Expand Down
5 changes: 2 additions & 3 deletions src/rules/__tests__/no-export.test.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
import { TSESLint } from '@typescript-eslint/utils';
import dedent from 'dedent';
import rule from '../no-export';
import { espreeParser } from './test-utils';
import { FlatCompatRuleTester, espreeParser } from './test-utils';

const ruleTester = new TSESLint.RuleTester({
const ruleTester = new FlatCompatRuleTester({
parser: espreeParser,
parserOptions: {
ecmaVersion: 2015,
Expand Down
5 changes: 2 additions & 3 deletions src/rules/__tests__/no-focused-tests.test.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
import { TSESLint } from '@typescript-eslint/utils';
import dedent from 'dedent';
import rule from '../no-focused-tests';
import { espreeParser } from './test-utils';
import { FlatCompatRuleTester, espreeParser } from './test-utils';

const ruleTester = new TSESLint.RuleTester({
const ruleTester = new FlatCompatRuleTester({
parser: espreeParser,
parserOptions: {
ecmaVersion: 6,
Expand Down
5 changes: 2 additions & 3 deletions src/rules/__tests__/no-hooks.test.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,9 @@
import { TSESLint } from '@typescript-eslint/utils';
import dedent from 'dedent';
import rule from '../no-hooks';
import { HookName } from '../utils';
import { espreeParser } from './test-utils';
import { FlatCompatRuleTester, espreeParser } from './test-utils';

const ruleTester = new TSESLint.RuleTester({
const ruleTester = new FlatCompatRuleTester({
parser: espreeParser,
parserOptions: {
ecmaVersion: 2015,
Expand Down
5 changes: 2 additions & 3 deletions src/rules/__tests__/no-identical-title.test.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
import { TSESLint } from '@typescript-eslint/utils';
import dedent from 'dedent';
import rule from '../no-identical-title';
import { espreeParser } from './test-utils';
import { FlatCompatRuleTester, espreeParser } from './test-utils';

const ruleTester = new TSESLint.RuleTester({
const ruleTester = new FlatCompatRuleTester({
parser: espreeParser,
parserOptions: {
ecmaVersion: 2015,
Expand Down
5 changes: 2 additions & 3 deletions src/rules/__tests__/no-interpolation-in-snapshots.test.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
import { TSESLint } from '@typescript-eslint/utils';
import rule from '../no-interpolation-in-snapshots';
import { espreeParser } from './test-utils';
import { FlatCompatRuleTester, espreeParser } from './test-utils';

const ruleTester = new TSESLint.RuleTester({
const ruleTester = new FlatCompatRuleTester({
parser: espreeParser,
parserOptions: {
ecmaVersion: 2017,
Expand Down
4 changes: 2 additions & 2 deletions src/rules/__tests__/no-jasmine-globals.test.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { TSESLint } from '@typescript-eslint/utils';
import rule from '../no-jasmine-globals';
import { FlatCompatRuleTester } from './test-utils';

const ruleTester = new TSESLint.RuleTester();
const ruleTester = new FlatCompatRuleTester();

ruleTester.run('no-jasmine-globals', rule, {
valid: [
Expand Down
Loading
Loading