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

fix: fix tsconfig-less check errors, fix @types/eslint incompatibilities, add tests #8460

Merged
merged 4 commits into from Feb 15, 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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
4 changes: 2 additions & 2 deletions eslint.config.mjs
Expand Up @@ -329,8 +329,8 @@ export default tseslint.config(
'packages/*/tests/**/spec.{ts,tsx,cts,mts}',
'packages/*/tests/**/test.{ts,tsx,cts,mts}',
'packages/parser/tests/**/*.{ts,tsx,cts,mts}',
'packages/integration-tests/tools/integration-test-base.{ts,tsx,cts,mts}',
'packages/integration-tests/tools/pack-packages.{ts,tsx,cts,mts}',
'packages/integration-tests/tools/integration-test-base.ts',
'packages/integration-tests/tools/pack-packages.ts',
],
rules: {
'@typescript-eslint/no-empty-function': [
Expand Down
@@ -0,0 +1,2 @@
// a hacky way to allow __dirname within ESM
module.exports = __dirname;
@@ -0,0 +1,57 @@
// @ts-check

import { FlatCompat } from '@eslint/eslintrc';
import eslint from '@eslint/js';
import stylisticPlugin from '@stylistic/eslint-plugin';
import deprecationPlugin from 'eslint-plugin-deprecation';
import jestPlugin from 'eslint-plugin-jest';
import tseslint from 'typescript-eslint';

import __dirname from './dirname.cjs';

const compat = new FlatCompat({
baseDirectory: __dirname,
recommendedConfig: {},
allConfig: {},
});

// this config is run through eslint as part of the integration test
// so it needs to be a correct config
export default tseslint.config(
{
plugins: {
['@typescript-eslint']: tseslint.plugin,
['deprecation']: deprecationPlugin,
['jest']: jestPlugin,
},
},
eslint.configs.recommended,
...tseslint.configs.recommended,
stylisticPlugin.configs['recommended-flat'],
);

// these are just tests for the types and are not seen by eslint so they can be whatever
tseslint.config({
plugins: {
['@stylistic']: stylisticPlugin,
['@typescript-eslint']: tseslint.plugin,
['deprecation']: deprecationPlugin,
['jest']: jestPlugin,
},
});
tseslint.config(
eslint.configs.recommended,
...tseslint.configs.recommended,
stylisticPlugin.configs['recommended-flat'],
);
tseslint.config(
// @ts-expect-error
compat.config(deprecationPlugin.configs.recommended),
...compat.config(jestPlugin.configs.recommended),
);
tseslint.config(
// @ts-expect-error
deprecationPlugin.configs.recommended,
// this should error but doesn't because there are no types exported from the jest plugin
jestPlugin.configs.recommended,
);
14 changes: 14 additions & 0 deletions packages/integration-tests/fixtures/flat-config-types/package.json
@@ -0,0 +1,14 @@
{
"type": "module",
"devDependencies": {
"@types/eslint__eslintrc": "latest",
"@eslint/eslintrc": "latest",
"@types/eslint__js": "latest",
"@eslint/js": "latest",
"@types/eslint": "latest",
"eslint": "latest",
"@stylistic/eslint-plugin": "latest",
"eslint-plugin-deprecation": "latest",
"eslint-plugin-jest": "latest"
}
}
@@ -1,6 +1,6 @@
// Jest Snapshot v1, https://goo.gl/fbAQLP

exports[`eslint-v8 should lint successfully 1`] = `
exports[`eslint-v8 eslint should work successfully 1`] = `
[
{
"errorCount": 1,
Expand Down
@@ -0,0 +1,107 @@
// Jest Snapshot v1, https://goo.gl/fbAQLP

exports[`flat-config-types eslint should work successfully 1`] = `
[
{
"errorCount": 2,
"fatalErrorCount": 0,
"filePath": "<root>/eslint.config.js",
"fixableErrorCount": 0,
"fixableWarningCount": 0,
"messages": [
{
"column": 3,
"endColumn": 22,
"endLine": 48,
"line": 48,
"message": "Include a description after the "@ts-expect-error" directive to explain why the @ts-expect-error is necessary. The description must be 3 characters or longer.",
"messageId": "tsDirectiveCommentRequiresDescription",
"nodeType": "Line",
"ruleId": "@typescript-eslint/ban-ts-comment",
"severity": 2,
},
{
"column": 3,
"endColumn": 22,
"endLine": 53,
"line": 53,
"message": "Include a description after the "@ts-expect-error" directive to explain why the @ts-expect-error is necessary. The description must be 3 characters or longer.",
"messageId": "tsDirectiveCommentRequiresDescription",
"nodeType": "Line",
"ruleId": "@typescript-eslint/ban-ts-comment",
"severity": 2,
},
],
"output": "// @ts-check

import { FlatCompat } from '@eslint/eslintrc'
import eslint from '@eslint/js'
import stylisticPlugin from '@stylistic/eslint-plugin'
import deprecationPlugin from 'eslint-plugin-deprecation'
import jestPlugin from 'eslint-plugin-jest'
import tseslint from 'typescript-eslint'

import __dirname from './dirname.cjs'

const compat = new FlatCompat({
baseDirectory: __dirname,
recommendedConfig: {},
allConfig: {},
})

// this config is run through eslint as part of the integration test
// so it needs to be a correct config
export default tseslint.config(
{
plugins: {
['@typescript-eslint']: tseslint.plugin,
['deprecation']: deprecationPlugin,
['jest']: jestPlugin,
},
},
eslint.configs.recommended,
...tseslint.configs.recommended,
stylisticPlugin.configs['recommended-flat'],
)

// these are just tests for the types and are not seen by eslint so they can be whatever
tseslint.config({
plugins: {
['@stylistic']: stylisticPlugin,
['@typescript-eslint']: tseslint.plugin,
['deprecation']: deprecationPlugin,
['jest']: jestPlugin,
},
})
tseslint.config(
eslint.configs.recommended,
...tseslint.configs.recommended,
stylisticPlugin.configs['recommended-flat'],
)
tseslint.config(
// @ts-expect-error
compat.config(deprecationPlugin.configs.recommended),
...compat.config(jestPlugin.configs.recommended),
)
tseslint.config(
// @ts-expect-error
deprecationPlugin.configs.recommended,
// this should error but doesn't because there are no types exported from the jest plugin
jestPlugin.configs.recommended,
)
",
"suppressedMessages": [],
"usedDeprecatedRules": [
{
"replacedBy": [],
"ruleId": "no-extra-semi",
},
{
"replacedBy": [],
"ruleId": "no-mixed-spaces-and-tabs",
},
],
"warningCount": 0,
},
]
`;
@@ -1,6 +1,6 @@
// Jest Snapshot v1, https://goo.gl/fbAQLP

exports[`markdown should lint successfully 1`] = `
exports[`markdown eslint should work successfully 1`] = `
[
{
"errorCount": 10,
Expand Down
@@ -1,6 +1,6 @@
// Jest Snapshot v1, https://goo.gl/fbAQLP

exports[`recommended-does-not-require-program should lint successfully 1`] = `
exports[`recommended-does-not-require-program eslint should work successfully 1`] = `
[
{
"errorCount": 1,
Expand Down
@@ -1,6 +1,6 @@
// Jest Snapshot v1, https://goo.gl/fbAQLP

exports[`typescript-and-tslint-plugins-together should lint successfully 1`] = `
exports[`typescript-and-tslint-plugins-together eslint should work successfully 1`] = `
[
{
"errorCount": 1,
Expand Down
@@ -1,6 +1,6 @@
// Jest Snapshot v1, https://goo.gl/fbAQLP

exports[`vue-jsx should lint successfully 1`] = `
exports[`vue-jsx eslint should work successfully 1`] = `
[
{
"errorCount": 1,
Expand Down
@@ -1,6 +1,6 @@
// Jest Snapshot v1, https://goo.gl/fbAQLP

exports[`vue-sfc should lint successfully 1`] = `
exports[`vue-sfc eslint should work successfully 1`] = `
[
{
"errorCount": 1,
Expand Down
4 changes: 2 additions & 2 deletions packages/integration-tests/tests/eslint-v8.test.ts
@@ -1,3 +1,3 @@
import { integrationTest } from '../tools/integration-test-base';
import { eslintIntegrationTest } from '../tools/integration-test-base';

integrationTest(__filename, '*.ts');
eslintIntegrationTest(__filename, '*.ts');
37 changes: 37 additions & 0 deletions packages/integration-tests/tests/flat-config-types.test.ts
@@ -0,0 +1,37 @@
import {
eslintIntegrationTest,
typescriptIntegrationTest,
} from '../tools/integration-test-base';

typescriptIntegrationTest(
__filename,
['--allowJs', '--esModuleInterop', 'eslint.config.js'],
out => {
const lines = out
.split('\n')
.filter(
line =>
// error TS18028: Private identifiers are only available when targeting ECMAScript 2015 and higher.
// this is fine for us to ignore in this context
!line.includes('error TS18028'),
)
.join('\n');

// The stylistic type errors: https://github.com/eslint-stylistic/eslint-stylistic/issues/276
expect(lines).toMatchInlineSnapshot(`
"node_modules/@stylistic/eslint-plugin-plus/dts/index.d.ts(7,46): error TS2694: Namespace '"/<tmp_folder>/node_modules/@types/eslint/index".ESLint' has no exported member 'RuleModule'.
node_modules/@stylistic/eslint-plugin/dist/dts/rule-options.d.ts(6,11): error TS2320: Interface 'UnprefixedRuleOptions' cannot simultaneously extend types 'UnprefixedRuleOptions' and 'UnprefixedRuleOptions'.
Named property ''comma-dangle'' of types 'UnprefixedRuleOptions' and 'UnprefixedRuleOptions' are not identical.
node_modules/@stylistic/eslint-plugin/dist/dts/rule-options.d.ts(6,11): error TS2320: Interface 'UnprefixedRuleOptions' cannot simultaneously extend types 'UnprefixedRuleOptions' and 'UnprefixedRuleOptions'.
Named property ''keyword-spacing'' of types 'UnprefixedRuleOptions' and 'UnprefixedRuleOptions' are not identical.
node_modules/@stylistic/eslint-plugin/dist/dts/rule-options.d.ts(6,11): error TS2320: Interface 'UnprefixedRuleOptions' cannot simultaneously extend types 'UnprefixedRuleOptions' and 'UnprefixedRuleOptions'.
Named property ''lines-around-comment'' of types 'UnprefixedRuleOptions' and 'UnprefixedRuleOptions' are not identical.
node_modules/@stylistic/eslint-plugin/dist/dts/rule-options.d.ts(6,11): error TS2320: Interface 'UnprefixedRuleOptions' cannot simultaneously extend types 'UnprefixedRuleOptions' and 'UnprefixedRuleOptions'.
Named property ''lines-between-class-members'' of types 'UnprefixedRuleOptions' and 'UnprefixedRuleOptions' are not identical.
node_modules/@stylistic/eslint-plugin/dist/dts/rule-options.d.ts(6,11): error TS2320: Interface 'UnprefixedRuleOptions' cannot simultaneously extend types 'UnprefixedRuleOptions' and 'UnprefixedRuleOptions'.
Named property ''padding-line-between-statements'' of types 'UnprefixedRuleOptions' and 'UnprefixedRuleOptions' are not identical.
"
`);
},
);
eslintIntegrationTest(__filename, 'eslint.config.js', true);
4 changes: 2 additions & 2 deletions packages/integration-tests/tests/markdown.test.ts
@@ -1,3 +1,3 @@
import { integrationTest } from '../tools/integration-test-base';
import { eslintIntegrationTest } from '../tools/integration-test-base';

integrationTest(__filename, '*.md');
eslintIntegrationTest(__filename, '*.md');
@@ -1,3 +1,3 @@
import { integrationTest } from '../tools/integration-test-base';
import { eslintIntegrationTest } from '../tools/integration-test-base';

integrationTest(__filename, '*.ts');
eslintIntegrationTest(__filename, '*.ts');
@@ -1,3 +1,3 @@
import { integrationTest } from '../tools/integration-test-base';
import { eslintIntegrationTest } from '../tools/integration-test-base';

integrationTest(__filename, '*.ts');
eslintIntegrationTest(__filename, '*.ts');
4 changes: 2 additions & 2 deletions packages/integration-tests/tests/vue-jsx.test.ts
@@ -1,3 +1,3 @@
import { integrationTest } from '../tools/integration-test-base';
import { eslintIntegrationTest } from '../tools/integration-test-base';

integrationTest(__filename, '*.vue');
eslintIntegrationTest(__filename, '*.vue');
4 changes: 2 additions & 2 deletions packages/integration-tests/tests/vue-sfc.test.ts
@@ -1,3 +1,3 @@
import { integrationTest } from '../tools/integration-test-base';
import { eslintIntegrationTest } from '../tools/integration-test-base';

integrationTest(__filename, '*.vue');
eslintIntegrationTest(__filename, '*.vue');