@haltcase/style 6.2.1 → 7.0.0-canary.10

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (61) hide show
  1. package/eslint/configs/browser.js +27 -0
  2. package/eslint/configs/cjs.js +13 -0
  3. package/eslint/configs/internal/base.js +178 -0
  4. package/eslint/configs/internal/commonjs.js +22 -0
  5. package/eslint/{rules → configs/internal}/es2015.js +17 -16
  6. package/eslint/configs/internal/simple-import-sort.js +27 -0
  7. package/eslint/configs/internal/tsdoc.js +20 -0
  8. package/eslint/{rules → configs/internal}/unicorn.js +118 -126
  9. package/eslint/configs/next.js +50 -0
  10. package/eslint/configs/node.js +27 -0
  11. package/eslint/configs/playwright-test.js +21 -0
  12. package/eslint/configs/react.js +109 -0
  13. package/eslint/configs/typescript.js +106 -0
  14. package/eslint/constants.js +23 -28
  15. package/eslint/index.js +33 -0
  16. package/eslint/rules/best-practice.js +250 -245
  17. package/eslint/rules/imports.js +94 -0
  18. package/eslint/rules/jsx-a11y.js +11 -10
  19. package/eslint/rules/playwright-test.js +25 -26
  20. package/eslint/rules/possible-errors.js +38 -45
  21. package/eslint/rules/react-x.js +78 -0
  22. package/eslint/rules/react.js +20 -113
  23. package/eslint/rules/stylistic-jsx.js +17 -0
  24. package/eslint/rules/stylistic.js +83 -84
  25. package/eslint/rules/typescript/extension.js +68 -39
  26. package/eslint/rules/typescript/import.js +16 -15
  27. package/eslint/rules/typescript/index.js +110 -121
  28. package/eslint/rules/typescript/naming-convention.js +121 -0
  29. package/eslint/rules/variables.js +34 -34
  30. package/eslint/withFiles.js +15 -0
  31. package/package.json +53 -59
  32. package/prettier/index.js +4 -11
  33. package/readme.md +183 -98
  34. package/stylelint/_base.js +2 -4
  35. package/stylelint/index.js +6 -7
  36. package/stylelint/modules.js +7 -8
  37. package/stylelint/standard.js +2 -5
  38. package/typescript/tsconfig.base.json +2 -1
  39. package/typescript/tsconfig.bundler.json +7 -3
  40. package/typescript/tsconfig.next.json +14 -6
  41. package/typescript/tsconfig.node.json +1 -1
  42. package/typescript/tsconfig.node18.json +4 -7
  43. package/typescript/tsconfig.node20.json +4 -7
  44. package/typescript/tsconfig.node22.json +10 -0
  45. package/typescript/tsconfig.web.json +1 -1
  46. package/eslint/_base.js +0 -82
  47. package/eslint/astro.js +0 -40
  48. package/eslint/browser.js +0 -8
  49. package/eslint/cjs.js +0 -12
  50. package/eslint/jest.js +0 -28
  51. package/eslint/next.js +0 -38
  52. package/eslint/node.js +0 -8
  53. package/eslint/playwright-test.js +0 -8
  54. package/eslint/react.js +0 -18
  55. package/eslint/rules/import.js +0 -92
  56. package/eslint/rules/jest.js +0 -28
  57. package/eslint/rules/simple-import-sort.js +0 -23
  58. package/eslint/rules/tsdoc.js +0 -17
  59. package/eslint/rules/typescript/strict.js +0 -18
  60. package/eslint/typescript.js +0 -26
  61. package/eslint/utils/require-package.js +0 -44
@@ -0,0 +1,27 @@
1
+ import globals from "globals";
2
+ import { config } from "typescript-eslint";
3
+
4
+ import { getEslintBaseConfig } from "./internal/base.js";
5
+
6
+ /**
7
+ * @type {import("./internal/base.js").HaltcaseStyleCreator}
8
+ */
9
+ export const getEslintBrowserConfig = (options = {}) =>
10
+ config(
11
+ ...getEslintBaseConfig(options),
12
+ ...getEslintBrowserConfigInternal(options)
13
+ );
14
+
15
+ /**
16
+ * @type {import("./internal/base.js").HaltcaseStyleCreator}
17
+ */
18
+ export const getEslintBrowserConfigInternal = (_options = {}) =>
19
+ config({
20
+ name: "Browser",
21
+
22
+ languageOptions: {
23
+ globals: {
24
+ ...globals.browser
25
+ }
26
+ }
27
+ });
@@ -0,0 +1,13 @@
1
+ import { config } from "typescript-eslint";
2
+
3
+ import { getEslintBaseConfig } from "./internal/base.js";
4
+ import { getEslintCommonJsConfigInternal } from "./internal/commonjs.js";
5
+
6
+ /**
7
+ * @type {import("./internal/base.js").HaltcaseStyleCreator}
8
+ */
9
+ export const getEslintCommonJsConfig = (options) =>
10
+ config(
11
+ ...getEslintBaseConfig(options),
12
+ ...getEslintCommonJsConfigInternal(options)
13
+ );
@@ -0,0 +1,178 @@
1
+ /**
2
+ * @import { ParserOptions } from "@typescript-eslint/types"
3
+ */
4
+
5
+ import babelParser from "@babel/eslint-parser";
6
+ import eslint from "@eslint/js";
7
+ import eslintPluginEslintComments from "@eslint-community/eslint-plugin-eslint-comments";
8
+ import eslintConfigPrettier from "eslint-config-prettier";
9
+ import eslintPluginImportX from "eslint-plugin-import-x";
10
+ import eslintRegexp from "eslint-plugin-regexp";
11
+ import { config } from "typescript-eslint";
12
+
13
+ import {
14
+ allSupportedFiles,
15
+ configFiles,
16
+ ecmaVersion,
17
+ javascriptFiles,
18
+ scriptFiles
19
+ } from "../../constants.js";
20
+ import { bestPracticeRules } from "../../rules/best-practice.js";
21
+ import { importRules } from "../../rules/imports.js";
22
+ import { possibleErrorsRules } from "../../rules/possible-errors.js";
23
+ import { stylisticRules } from "../../rules/stylistic.js";
24
+ import { variablesRules } from "../../rules/variables.js";
25
+ import { getEslintTypescriptConfig } from "../typescript.js";
26
+ import { getEslintCommonJsConfigInternal } from "./commonjs.js";
27
+ import { eslintEs2015Config } from "./es2015.js";
28
+ import { eslintSimpleImportSortConfig } from "./simple-import-sort.js";
29
+ import { eslintUnicornConfig } from "./unicorn.js";
30
+
31
+ /**
32
+ * @typedef {Object} HaltcaseStyleOptions
33
+ * @property {boolean} [browser] Whether to include browser rules and globals.
34
+ * @property {boolean} [commonjs] Whether to treat *.js files as CommonJS instead of ES Modules.
35
+ * @property {boolean} [nextjs] Whether to include Next.js rules (implies `react`).
36
+ * @property {boolean} [node] Whether to include Node.js rules.
37
+ * @property {boolean} [react] Whether to include React rules.
38
+ * @property {ParserOptions["project"]} [typescriptProject = true] Custom TypeScript project options for the `typescript-eslint` parser.
39
+ * // use when VS Code supports `projectService`
40
+ * // https://github.com/microsoft/vscode-eslint/issues/1911
41
+ * property {ProjectServiceOptions} [typescriptProjectServiceOptions = true] Custom TypeScript project service options for the `typescript-eslint` parser.
42
+ */
43
+
44
+ /**
45
+ * @typedef {(options?: HaltcaseStyleOptions) => Awaited<import("typescript-eslint").Config>} HaltcaseStyleCreator
46
+ */
47
+
48
+ /**
49
+ * Get the common ESLint config for Node and browsers.
50
+ *
51
+ * @type {HaltcaseStyleCreator}
52
+ */
53
+ export const getEslintBaseConfig = (options = {}) =>
54
+ config(
55
+ {
56
+ name: "import-x/recommended",
57
+ plugins: {
58
+ "import-x": eslintPluginImportX
59
+ },
60
+ rules: {
61
+ ...eslintPluginImportX.configs.recommended.rules
62
+ },
63
+ settings: {
64
+ "import-x/parsers": {
65
+ "@typescript-eslint/parser": [".ts"]
66
+ },
67
+ "import-x/resolver": {
68
+ typescript: true,
69
+ node: true
70
+ }
71
+ }
72
+ },
73
+
74
+ {
75
+ name: "@haltcase/internal/base",
76
+
77
+ extends: [
78
+ { name: "eslint/recommended", ...eslint.configs.recommended },
79
+
80
+ { name: "prettier", ...eslintConfigPrettier },
81
+
82
+ {
83
+ name: "eslint-comments",
84
+ rules: {
85
+ ...eslintPluginEslintComments.configs.recommended.rules
86
+ }
87
+ }
88
+ ],
89
+ languageOptions: {
90
+ // global parser options
91
+ parserOptions: {
92
+ ecmaVersion,
93
+ sourceType: "module"
94
+ }
95
+ },
96
+ linterOptions: {
97
+ reportUnusedDisableDirectives: "warn"
98
+ },
99
+ plugins: {
100
+ "@eslint-community/eslint-comments": eslintPluginEslintComments
101
+ }
102
+ },
103
+
104
+ {
105
+ name: "@haltcase/internal/Best practices",
106
+ files: allSupportedFiles,
107
+ rules: bestPracticeRules
108
+ },
109
+
110
+ ...eslintEs2015Config,
111
+
112
+ {
113
+ name: "@haltcase/internal/Imports",
114
+ files: allSupportedFiles,
115
+ rules: importRules
116
+ },
117
+
118
+ {
119
+ name: "@haltcase/internal/Possible errors",
120
+ files: allSupportedFiles,
121
+ rules: possibleErrorsRules
122
+ },
123
+
124
+ {
125
+ name: "@haltcase/internal/Regular Expressions",
126
+ // eslint-disable-next-line import-x/no-named-as-default-member
127
+ ...eslintRegexp.configs["flat/recommended"]
128
+ },
129
+
130
+ ...eslintSimpleImportSortConfig,
131
+
132
+ {
133
+ name: "@haltcase/internal/Stylistic",
134
+ files: allSupportedFiles,
135
+ rules: stylisticRules
136
+ },
137
+
138
+ ...eslintUnicornConfig,
139
+
140
+ {
141
+ name: "@haltcase/internal/Variables",
142
+ // files: allSupportedFiles,
143
+ rules: variablesRules
144
+ },
145
+
146
+ {
147
+ name: "@haltcase/internal/JavaScript files",
148
+ files: javascriptFiles,
149
+ languageOptions: {
150
+ parser: babelParser,
151
+ parserOptions: {
152
+ requireConfigFile: false
153
+ }
154
+ }
155
+ },
156
+
157
+ ...getEslintTypescriptConfig(options),
158
+
159
+ {
160
+ name: "@haltcase/internal/Third-party config files (e.g., next.config.mjs)",
161
+ files: configFiles,
162
+ rules: {
163
+ // these files likely require default exports
164
+ "import-x/no-default-export": "off"
165
+ }
166
+ },
167
+
168
+ {
169
+ name: "@haltcase/internal/Development-only helper scripts & Prisma database scripts",
170
+ files: scriptFiles,
171
+ rules: {
172
+ "no-console": "off",
173
+ "unicorn/no-process-exit": "off"
174
+ }
175
+ },
176
+
177
+ ...getEslintCommonJsConfigInternal(options)
178
+ );
@@ -0,0 +1,22 @@
1
+ import { config } from "typescript-eslint";
2
+
3
+ import { commonJsFiles, commonJsOnlyFiles } from "../../constants.js";
4
+
5
+ /**
6
+ * @type {import("./base.js").HaltcaseStyleCreator}
7
+ */
8
+ export const getEslintCommonJsConfigInternal = (options = {}) =>
9
+ config({
10
+ name: "@haltcase/internal/CommonJS files",
11
+
12
+ files: options.commonjs ? commonJsFiles : commonJsOnlyFiles,
13
+ languageOptions: {
14
+ parserOptions: {
15
+ sourceType: "script"
16
+ }
17
+ },
18
+ rules: {
19
+ strict: ["error", "global"],
20
+ "unicorn/prefer-module": "off"
21
+ }
22
+ });
@@ -1,71 +1,72 @@
1
- "use strict";
1
+ import { config } from "typescript-eslint";
2
2
 
3
- const {
4
- levels: { warn, error }
5
- } = require("../constants");
3
+ /**
4
+ * @type {ReturnType<import("./base.js").HaltcaseStyleCreator>}
5
+ */
6
+ export const eslintEs2015Config = config({
7
+ name: "@haltcase/internal/ES2015",
6
8
 
7
- module.exports = {
8
9
  rules: {
9
10
  /**
10
11
  * Disallow useless computed property keys.
11
12
  *
12
13
  * 🔧 Fixable - https://eslint.org/docs/rules/no-useless-computed-key
13
14
  */
14
- "no-useless-computed-key": warn,
15
+ "no-useless-computed-key": "warn",
15
16
  /**
16
17
  * Disallow renaming import, export, and destructured assignments to the
17
18
  * same name.
18
19
  *
19
20
  * 🔧 Fixable - https://eslint.org/docs/rules/no-useless-rename
20
21
  */
21
- "no-useless-rename": warn,
22
+ "no-useless-rename": "warn",
22
23
  /**
23
24
  * Require `let` or `const` instead of `var`.
24
25
  *
25
26
  * 🔧 Fixable - https://eslint.org/docs/rules/no-var
26
27
  */
27
- "no-var": error,
28
+ "no-var": "error",
28
29
  /**
29
30
  * Require object literal shorthand syntax.
30
31
  *
31
32
  * 🔧 Fixable - https://eslint.org/docs/rules/object-shorthand
32
33
  */
33
- "object-shorthand": warn,
34
+ "object-shorthand": "warn",
34
35
  /**
35
36
  * Require default to `const` instead of `let`.
36
37
  *
37
38
  * 🔧 Fixable - https://eslint.org/docs/rules/prefer-const
38
39
  */
39
- "prefer-const": warn,
40
+ "prefer-const": "warn",
40
41
  /**
41
42
  * Disallow parseInt() in favor of binary, octal, and hexadecimal literals.
42
43
  *
43
44
  * 🔧 Fixable - https://eslint.org/docs/rules/prefer-numeric-literals
44
45
  */
45
- "prefer-numeric-literals": error,
46
+ "prefer-numeric-literals": "error",
46
47
  /**
47
48
  * Require using rest parameters instead of `arguments`.
48
49
  *
49
50
  * 🚫 Not fixable - https://eslint.org/docs/rules/prefer-rest-params
50
51
  */
51
- "prefer-rest-params": error,
52
+ "prefer-rest-params": "error",
52
53
  /**
53
54
  * Require using spread syntax instead of `.apply()`.
54
55
  *
55
56
  * 🚫 Not fixable - https://eslint.org/docs/rules/prefer-spread
56
57
  */
57
- "prefer-spread": error,
58
+ "prefer-spread": "error",
58
59
  /**
59
60
  * Require using template literals instead of string concatenation.
60
61
  *
61
62
  * 🔧 Fixable - https://eslint.org/docs/rules/prefer-template
62
63
  */
63
- "prefer-template": warn,
64
+ "prefer-template": "warn",
64
65
  /**
65
66
  * Require a `Symbol` description.
66
67
  *
67
68
  * 🚫 Not fixable - https://eslint.org/docs/rules/symbol-description
68
69
  */
69
- "symbol-description": error
70
+ "symbol-description": "error"
70
71
  }
71
- };
72
+ });
@@ -0,0 +1,27 @@
1
+ import eslintPluginSimpleImportSort from "eslint-plugin-simple-import-sort";
2
+ import { config } from "typescript-eslint";
3
+
4
+ /**
5
+ * @type {ReturnType<import("./base.js").HaltcaseStyleCreator>}
6
+ */
7
+ export const eslintSimpleImportSortConfig = config({
8
+ name: "@haltcase/internal/Import & export sorting",
9
+
10
+ plugins: {
11
+ "simple-import-sort": eslintPluginSimpleImportSort
12
+ },
13
+ rules: {
14
+ /**
15
+ * Enforce export sort order.
16
+ *
17
+ * 🔧 Fixable - https://github.com/lydell/eslint-plugin-simple-import-sort#exports
18
+ */
19
+ "simple-import-sort/exports": "error",
20
+ /**
21
+ * Enforce import sort order.
22
+ *
23
+ * 🔧 Fixable - https://github.com/lydell/eslint-plugin-simple-import-sort#imports
24
+ */
25
+ "simple-import-sort/imports": "error"
26
+ }
27
+ });
@@ -0,0 +1,20 @@
1
+ import eslintPluginTsdoc from "eslint-plugin-tsdoc";
2
+ import { config } from "typescript-eslint";
3
+
4
+ /**
5
+ * @type {ReturnType<import("./base.js").HaltcaseStyleCreator>}
6
+ */
7
+ export const eslintTsdocConfig = config({
8
+ name: "@haltcase/internal/TSDoc comments",
9
+ plugins: {
10
+ tsdoc: eslintPluginTsdoc
11
+ },
12
+ rules: {
13
+ /**
14
+ * Require TSDoc comments conform to the TSDoc specification.
15
+ *
16
+ * 🚫 Not fixable - https://github.com/microsoft/tsdoc/tree/master/eslint-plugin
17
+ */
18
+ "tsdoc/syntax": "error"
19
+ }
20
+ });