mirror of
https://github.com/bitwarden/browser
synced 2025-12-10 13:23:34 +00:00
* fix(enums-eslint): Enum Rule for ESLint - Added enums in the warnings for eslint. * fix(enums-eslint): Enum Rule for ESLint - Updated to error in both places for enums. * fix(enums-eslint): Enum Rule for ESLint - Added new eslint plugin for warning on enums. * fix(enums-eslint): Enum Rule for ESLint - Changed based on suggestion. Co-authored-by: Andreas Coroiu <acoroiu@bitwarden.com> * refactor(browser-platform-utils): Remove Deprecation and Fix Code - Changed usages of firefox to private and moved the usages to the preferred public method and removed the deprecations. * fix(enums-eslint): Enum Rule for ESLint - Updated to error and added disable rules for all other places. * fix(enums-eslint): Enum Rule for ESLint - Undid other changes by accident
72 lines
1.4 KiB
JavaScript
72 lines
1.4 KiB
JavaScript
import { RuleTester } from "@typescript-eslint/rule-tester";
|
|
|
|
import rule, { errorMessage } from "./no-enums.mjs";
|
|
|
|
const ruleTester = new RuleTester({
|
|
languageOptions: {
|
|
parserOptions: {
|
|
project: [__dirname + "/../tsconfig.spec.json"],
|
|
projectService: {
|
|
allowDefaultProject: ["*.ts*"],
|
|
},
|
|
tsconfigRootDir: __dirname + "/..",
|
|
},
|
|
},
|
|
});
|
|
|
|
ruleTester.run("no-enums", rule.default, {
|
|
valid: [
|
|
{
|
|
name: "Using const instead of enum",
|
|
code: `
|
|
const Status = {
|
|
Active: "active",
|
|
Inactive: "inactive",
|
|
} as const;
|
|
`,
|
|
},
|
|
{
|
|
name: "Using const with type",
|
|
code: `
|
|
const Status = {
|
|
Active: "active",
|
|
Inactive: "inactive",
|
|
} as const;
|
|
type Status = typeof Status[keyof typeof Status];
|
|
`,
|
|
},
|
|
],
|
|
invalid: [
|
|
{
|
|
name: "Using enum declaration",
|
|
code: `
|
|
enum Status {
|
|
Active = "active",
|
|
Inactive = "inactive",
|
|
}
|
|
`,
|
|
errors: [
|
|
{
|
|
message: errorMessage,
|
|
},
|
|
],
|
|
},
|
|
{
|
|
name: "Using enum with numeric values",
|
|
code: `
|
|
enum Direction {
|
|
Up = 1,
|
|
Down = 2,
|
|
Left = 3,
|
|
Right = 4,
|
|
}
|
|
`,
|
|
errors: [
|
|
{
|
|
message: errorMessage,
|
|
},
|
|
],
|
|
},
|
|
],
|
|
});
|