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

Support TypeScript 5.2.2 #338

Open
wants to merge 5 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 2 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,648 changes: 2,361 additions & 287 deletions package-lock.json

Large diffs are not rendered by default.

9 changes: 6 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
"description": "ESLint rules for TypeScript enums.",
"main": "dist",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1",
"test": "vitest",
"prebuild": "rimraf dist",
"build": "tsc",
"prepublishOnly": "npm run build"
Expand All @@ -31,12 +31,15 @@
},
"homepage": "https://github.com/shian15810/eslint-plugin-typescript-enum#readme",
"dependencies": {
"@typescript-eslint/experimental-utils": "^5.3.0"
"@typescript-eslint/utils": "^6.7.2"
Copy link
Author

Choose a reason for hiding this comment

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

This is the main change, and what removes the nested problematic tsutils package from the dependency tree: typescript-eslint/typescript-eslint#7155 (comment)

@shian15810 what do you think about this?

Copy link
Owner

Choose a reason for hiding this comment

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

Could you bump this to major version 8 of @typescript-eslint/utils? Its latest version is currently 8.18.0.

Copy link
Author

Choose a reason for hiding this comment

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

Done!

34496c5

},
"devDependencies": {
"@types/node": "^16.11.6",
"@typescript-eslint/parser": "^6.7.0",
"@typescript-eslint/rule-tester": "^6.7.0",
"rimraf": "^3.0.2",
"typesafeconfig": "^4.3.0",
"typescript": "^4.4.4"
"typescript": "^5.2.2",
"vitest": "^0.34.4"
}
}
17 changes: 17 additions & 0 deletions setupTests.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
/*
As recommended in the vitest docs: https://typescript-eslint.io/packages/rule-tester#vitest

ESLint's RuleTester relies on some global hooks for tests. If they aren't available globally, your tests will fail with an error like:

```
Error: Missing definition for `afterAll` - you must set one using `RuleTester.afterAll` or there must be one defined globally as `afterAll`.`
```
*/

import * as vitest from 'vitest';
import { RuleTester } from '@typescript-eslint/rule-tester';

RuleTester.afterAll = vitest.afterAll;
RuleTester.it = vitest.it;
RuleTester.itOnly = vitest.it.only;
RuleTester.describe = vitest.describe;
18 changes: 18 additions & 0 deletions src/rules/no-const-enum.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
import { RuleTester } from '@typescript-eslint/rule-tester';
import rule from './no-const-enum';

const ruleTester = new RuleTester();

ruleTester.run('no-const-enum', rule, {
valid: ['const x = 1;', 'const oneEnum = { "ONE": "one" };', 'const enumTwo = { "TWO": "two" };', 'enum a { "KEY" = "VALUE" };'],
invalid: [
{
code: 'const enum a { "KEY" = "VALUE" };',
errors: [
{
messageId: 'noConstEnum',
},
],
},
],
});
26 changes: 26 additions & 0 deletions src/rules/no-enum.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
import { RuleTester } from '@typescript-eslint/rule-tester';
import rule from './no-enum';

const ruleTester = new RuleTester();

ruleTester.run('no-enum', rule, {
valid: ['const x = 1;', 'const oneEnum = { "ONE": "one" };', 'const enumTwo = { "TWO": "two" };'],
invalid: [
{
code: 'enum a { "KEY" = "VALUE" };',
errors: [
{
messageId: 'noEnum',
},
],
},
{
code: 'const enum a { "KEY" = "VALUE" };',
errors: [
{
messageId: 'noEnum',
},
],
},
],
});
2 changes: 1 addition & 1 deletion src/rules/no-enum.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ const noEnum = createRule<Options, MessageIds>({
type: "problem",
docs: {
description: "Disallow all types of TypeScript enums",
recommended: "error",
recommended: "recommended",
shian15810 marked this conversation as resolved.
Show resolved Hide resolved
},
messages: {
noEnum:
Expand Down
2 changes: 1 addition & 1 deletion src/util/createRule.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { ESLintUtils } from "@typescript-eslint/experimental-utils";
import { ESLintUtils } from "@typescript-eslint/utils";

const { version } = require("../../package.json");

Expand Down
1 change: 1 addition & 0 deletions tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
"extends": "typesafeconfig",
"compilerOptions": {
"module": "commonjs",
"moduleResolution": "Bundler",
Copy link
Author

Choose a reason for hiding this comment

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

Added to allow TS to continue to pick up the correct types.

typescript-eslint/typescript-eslint#7284

Contains a warning when building, but appears to still produce the same output.

Copy link
Owner

Choose a reason for hiding this comment

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

Does this issue persist into v8 of @typescript-eslint/utils?

Copy link
Author

Choose a reason for hiding this comment

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

It is fixed! Removed the patch in 34496c5.

"outDir": "dist"
}
}
7 changes: 7 additions & 0 deletions vite.config.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
import { defineConfig } from 'vitest/config'

export default defineConfig({
test: {
setupFiles: './setupTests.ts'
},
})