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 13 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 type { Config } from '@jest/types';
G-Rath marked this conversation as resolved.
Show resolved Hide resolved
import { version as typescriptESLintPluginVersion } from '@typescript-eslint/eslint-plugin/package.json';
import { version as eslintVersion } from 'eslint/package.json';
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.InitialOptions;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
} satisfies Config.InitialOptions;
} satisfies Config;

why satisfies instead of assigning?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

because assigning means it is Config - so all properties marked as required are such, and optional ones are that outside of the assignment; so TypeScript won't let us do things on those properties later down without existence checks - sadly it's not perfect: we've got to define properties we want to use since the type information is not retained after the assignment, which is why we've got coveragePathIgnorePatterns explicitly defined with its default values.

Having said that, I've not checked out Config.InitialOptions so that might change things

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ok so jest.Config is just a re-export of Config.InitialOptions - so yeah, we could do either or; I think using satisfies is slightly nicer though.

To make it a bit clearer:

image

that's what happens if you use assignment, and it's because to TypeScript config is type Config rather than the actual object we created.


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;
31 changes: 1 addition & 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 All @@ -104,6 +74,7 @@
"@babel/preset-typescript": "^7.3.3",
"@commitlint/cli": "^17.0.3",
"@commitlint/config-conventional": "^17.0.3",
"@jest/types": "^29.6.3",
G-Rath marked this conversation as resolved.
Show resolved Hide resolved
"@schemastore/package": "^0.0.10",
"@semantic-release/changelog": "^6.0.0",
"@semantic-release/git": "^10.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()) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why is this needed?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Because we're effectively running ESLint here per usual - so when using ESLint v9 we have to use flatconfig and when using pre-v9 we have to use legacy config.

While linter.verify supports being passed both types of configs, since we have call defineRule in pre-v9 (which errors in v9) this felt the cleanest way to address it (though either way we'll always need 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