@open-xchange/linter-presets 0.2.0 → 0.3.1

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.
package/CHANGELOG.md CHANGED
@@ -1,5 +1,16 @@
1
1
  # Changelog
2
2
 
3
+ ## [0.3.1] - 2024-08-01
4
+
5
+ - added: [ESLint] default ignore globs (`dist`, `gitlab-ci`, and others)
6
+ - changed: [ESLint] default values of `stylistic` option (indent 4 spaces, always semicolons, double quotes)
7
+
8
+ ## [0.3.0] - 2024-08-01
9
+
10
+ - chore: [ESLint] [major bump of `typescript-eslint` to v8](https://typescript-eslint.io/blog/announcing-typescript-eslint-v8/)
11
+ - removed: [ESLint] environment `env.tsconfig` (always using `projectService` of `typescript-eslint` instead)
12
+ - changed: [ESLint] pattern for unused variables is now `^_.` (instead `^_`) to detect dangling underscore imports
13
+
3
14
  ## [0.2.0] - 2024-07-31
4
15
 
5
16
  - chore: bump dependencies
@@ -17,6 +17,7 @@ export default function ts() {
17
17
  // suppress warning for new TypeScript versions
18
18
  languageOptions: {
19
19
  parserOptions: {
20
+ projectService: true,
20
21
  warnOnUnsupportedTypeScriptVersion: false,
21
22
  },
22
23
  },
@@ -32,7 +33,6 @@ export default function ts() {
32
33
  "@typescript-eslint/consistent-type-exports": "error",
33
34
  "@typescript-eslint/consistent-type-imports": ["error", { disallowTypeAnnotations: false }],
34
35
  "@typescript-eslint/default-param-last": "error",
35
- "@typescript-eslint/dot-notation": "error",
36
36
  "@typescript-eslint/explicit-function-return-type": ["error", {
37
37
  allowExpressions: true,
38
38
  allowTypedFunctionExpressions: true,
@@ -40,12 +40,11 @@ export default function ts() {
40
40
  allowConciseArrowFunctionExpressionsStartingWithVoid: true,
41
41
  }],
42
42
  "@typescript-eslint/no-array-constructor": "error",
43
- "@typescript-eslint/no-array-delete": "error",
44
43
  "@typescript-eslint/no-duplicate-type-constituents": "error",
45
44
  "@typescript-eslint/no-empty-function": ["error", {
46
45
  allow: ["private-constructors", "protected-constructors", "decoratedFunctions", "overrideMethods"],
47
46
  }],
48
- "@typescript-eslint/no-empty-interface": "off",
47
+ "@typescript-eslint/no-empty-object-type": ["error", { allowInterfaces: "always" }],
49
48
  "@typescript-eslint/no-explicit-any": "off",
50
49
  "@typescript-eslint/no-import-type-side-effects": "error",
51
50
  "@typescript-eslint/no-invalid-this": "error",
@@ -56,19 +55,11 @@ export default function ts() {
56
55
  "@typescript-eslint/no-redeclare": "error",
57
56
  "@typescript-eslint/no-shadow": ["error", { ignoreOnInitialization: true }],
58
57
  "@typescript-eslint/no-unnecessary-template-expression": "error",
59
- "@typescript-eslint/no-unsafe-enum-comparison": "error",
60
- "@typescript-eslint/no-unsafe-function-type": "error",
61
- "@typescript-eslint/no-unsafe-unary-minus": "error",
62
58
  "@typescript-eslint/no-unused-vars": ["error", NO_UNUSED_VARS_OPTIONS],
63
59
  "@typescript-eslint/no-useless-constructor": "error",
64
- "@typescript-eslint/no-wrapper-object-types": "error",
65
- "@typescript-eslint/only-throw-error": "error",
66
- "@typescript-eslint/prefer-find": "error",
67
60
  "@typescript-eslint/prefer-literal-enum-member": "error",
68
- "@typescript-eslint/prefer-nullish-coalescing": "off",
69
- "@typescript-eslint/prefer-promise-reject-errors": "error",
61
+ "@typescript-eslint/prefer-nullish-coalescing": ["error", { ignorePrimitives: true }],
70
62
  "@typescript-eslint/prefer-readonly": "error",
71
- "@typescript-eslint/require-await": "error",
72
63
  "@typescript-eslint/restrict-template-expressions": "off",
73
64
  "@typescript-eslint/return-await": ["error", "always"],
74
65
  "@typescript-eslint/switch-exhaustiveness-check": "error",
@@ -1,6 +1,5 @@
1
1
  import type { TSESLint } from "@typescript-eslint/utils";
2
2
  import type { LanguageOptions, StylisticOptions } from "./shared/env-utils.js";
3
- import tsconfig from "./env/tsconfig.js";
4
3
  import node from "./env/node.js";
5
4
  import browser from "./env/browser.js";
6
5
  import jest from "./env/jest.js";
@@ -40,7 +39,6 @@ export interface ConfigureOptions {
40
39
  * A collection with all available environment presets.
41
40
  */
42
41
  export declare const env: {
43
- tsconfig: typeof tsconfig;
44
42
  node: typeof node;
45
43
  browser: typeof browser;
46
44
  jest: typeof jest;
@@ -9,7 +9,6 @@ import imports from "./config/imports.js";
9
9
  import promises from "./config/promises.js";
10
10
  import jsdoc from "./config/jsdoc.js";
11
11
  import stylistic from "./config/stylistic.js";
12
- import tsconfig from "./env/tsconfig.js";
13
12
  import node from "./env/node.js";
14
13
  import browser from "./env/browser.js";
15
14
  import jest from "./env/jest.js";
@@ -23,7 +22,6 @@ import eslint from "./env/eslint.js";
23
22
  * A collection with all available environment presets.
24
23
  */
25
24
  export const env = {
26
- tsconfig,
27
25
  node,
28
26
  browser,
29
27
  jest,
@@ -45,6 +43,14 @@ export const env = {
45
43
  * An array of configuration objects to be added to the flat configuration.
46
44
  */
47
45
  export function configure(options) {
46
+ const ignores = [
47
+ "*/.yarn/*",
48
+ "dist/*",
49
+ "vite.config.ts.*.mjs",
50
+ "gitlab-ci/*",
51
+ ".gitlab-ci.yml",
52
+ ...(options?.ignores ?? []),
53
+ ];
48
54
  // resolve language configuration options
49
55
  const languageOptions = {
50
56
  ecmaVersion: 2022,
@@ -54,15 +60,15 @@ export function configure(options) {
54
60
  };
55
61
  // resolve stylistic configuration options
56
62
  const stylisticOptions = {
57
- indent: 2,
58
- semi: "never",
59
- quotes: "single",
63
+ indent: 4,
64
+ semi: "always",
65
+ quotes: "double",
60
66
  dangle: "always",
61
67
  ...options?.stylistic,
62
68
  };
63
69
  return [
64
70
  // ignore certain files and folders
65
- ...(options?.ignores?.length ? [{ ignores: options.ignores }] : []),
71
+ { ignores },
66
72
  // module types and standard rules for all JS/TS source files
67
73
  ...base(languageOptions),
68
74
  // default configuration for JavaScript files
@@ -1,3 +1,3 @@
1
1
  import { type TSESLint } from "@typescript-eslint/utils";
2
- declare const _default: TSESLint.RuleModule<"UNEXPECTED_DIRECTIVE" | "UNEXPECTED_DIRECTIVE_FIX", [], TSESLint.RuleListener>;
2
+ declare const _default: TSESLint.RuleModule<"UNEXPECTED_DIRECTIVE" | "UNEXPECTED_DIRECTIVE_FIX", [], unknown, TSESLint.RuleListener>;
3
3
  export default _default;
@@ -21,5 +21,5 @@ export interface RuleNoInvalidHierarchyPackage {
21
21
  export type RuleNoInvalidHierarchyOptions = Record<string, RuleNoInvalidHierarchyPackage>;
22
22
  type RuleOptions = [RuleNoInvalidHierarchyOptions];
23
23
  type RuleMessageIds = "UNEXPECTED_OPTIONAL_STATIC" | "INVALID_PACKAGE_HIERARCHY";
24
- declare const _default: ESLintUtils.RuleModule<RuleMessageIds, RuleOptions, ESLintUtils.RuleListener>;
24
+ declare const _default: ESLintUtils.RuleModule<RuleMessageIds, RuleOptions, unknown, ESLintUtils.RuleListener>;
25
25
  export default _default;
@@ -6,5 +6,5 @@ export interface RuleNoInvalidModulesOptions {
6
6
  external?: string[];
7
7
  }
8
8
  type RuleOptions = [Required<RuleNoInvalidModulesOptions>];
9
- declare const _default: ESLintUtils.RuleModule<"SOURCE_FILE_NOT_FOUND", RuleOptions, ESLintUtils.RuleListener>;
9
+ declare const _default: ESLintUtils.RuleModule<"SOURCE_FILE_NOT_FOUND", RuleOptions, unknown, ESLintUtils.RuleListener>;
10
10
  export default _default;
@@ -4,9 +4,9 @@
4
4
  * `@typescript-eslint/no-unused-vars`.
5
5
  */
6
6
  export const NO_UNUSED_VARS_OPTIONS = {
7
- varsIgnorePattern: "^_",
8
- argsIgnorePattern: "^_",
9
- destructuredArrayIgnorePattern: "^_",
7
+ varsIgnorePattern: "^_.",
8
+ argsIgnorePattern: "^_.",
9
+ destructuredArrayIgnorePattern: "^_.",
10
10
  caughtErrors: "all",
11
11
  ignoreRestSiblings: true,
12
12
  };
@@ -22,7 +22,7 @@ export const NO_UNUSED_VARS_OPTIONS = {
22
22
  * The concatenated and flattened array.
23
23
  */
24
24
  function flatten(...entries) {
25
- return entries.flatMap(array => array || []);
25
+ return entries.flatMap(array => array ?? []);
26
26
  }
27
27
  /**
28
28
  * Creates a rules record for all restricted items.
@@ -141,7 +141,7 @@ export function restrictedRules(envOptions, fixed) {
141
141
  * custom rule settings, otherwise `undefined`.
142
142
  */
143
143
  export function customRules(envOptions, rules) {
144
- return (rules || envOptions.rules) && createConfig(envOptions, {
144
+ return (rules ?? envOptions.rules) && createConfig(envOptions, {
145
145
  rules: { ...rules, ...envOptions.rules },
146
146
  });
147
147
  }
@@ -32,19 +32,29 @@ function configure(options?: ConfigureOptions): Linter.FlatConfig[]
32
32
 
33
33
  | Name | Type | Default | Description |
34
34
  | - | - | - | - |
35
- | `ignores` | `string[]` | `[]` | Glob patterns with all files and folders to be ignored by ESLint. |
35
+ | `ignores` | `string[]` | `[]` | Glob patterns with all files and folders to be ignored by ESLint. This package already defines a few standard ignore globs (see below). |
36
36
  | `license` | `string` | `""` | Full path to the template file containing the license header to be used in all source files. |
37
37
  | `language` | `LanguageOptions` | | Configuration options for language and project setup. |
38
38
  | `language.ecmaVersion` | `number` | `2022` | The ECMAScript version to be used in the project (version or year). |
39
39
  | `language.sourceType` | `"module"\|"commonjs"` | `"module"` | Specifies how to treat `.js`, `.jsx`, `.ts`, and `.tsx` files. |
40
40
  | `language.nativeDecorators` | `boolean` | `false` | Whether to support native ES decorators in JavaScript code (via Babel plugin). Does not affect TypeScript code which uses an own parser aware of the decorator syntax. |
41
41
  | `stylistic` | `StylisticOptions` | | Configuration options for code style. |
42
- | `stylistic.indent` | `number` | `2` | Default indentation size (number of space characters). Will be applied to JavaScript, TypeScript, JSON, and YAML files, as well as JSX markup. |
43
- | `stylistic.semi` | `boolean` | `false` | Specifies whether to require semicolons following all statements (`true`), or to force to omit semicolons if possible according to ASI rules (`false`). |
44
- | `stylistic.quotes` | `"single"\|"double"\|"off"` | `"single"` | The type of the string delimiter character. |
42
+ | `stylistic.indent` | `number` | `4` | Default indentation size (number of space characters). Will be applied to JavaScript, TypeScript, JSON, and YAML files, as well as JSX markup. |
43
+ | `stylistic.semi` | `"always"\|"never"\|"off"` | `"always"` | Specifies whether to require semicolons following all statements (`"always"`), or to force to omit semicolons if possible according to ASI rules (`"never"`). |
44
+ | `stylistic.quotes` | `"single"\|"double"\|"off"` | `"double"` | The type of the string delimiter character. |
45
45
  | `stylistic.dangle` | `"always"\|"never"\|"off"` | `"always"` | Specifies how to treat dangling commas in multiline lists. |
46
46
  | `rules` | `Linter.RulesRecord` | `{}` | Additional linter rules to be added to the global configuration. |
47
47
 
48
+ #### Built-in Ignore Globs
49
+
50
+ This package defines ignore globs for the following files and directories:
51
+
52
+ - `*/.yarn/*` (internal setup files of Yarn v2+)
53
+ - `dist/*` (standard build output directory)
54
+ - `vite.config.ts.*.mjs` (intermediate files of Vite dev server)
55
+ - `gitlab-ci/*` (GitLab CI configuration files)
56
+ - `.gitlab-ci.yml` (GitLab CI configuration files)
57
+
48
58
  #### `configure` Example
49
59
 
50
60
  ```js
@@ -73,7 +83,6 @@ The names of the environment presets are linked to detailed descriptions.
73
83
 
74
84
  | Name | Description |
75
85
  | - | - |
76
- | [`env.tsconfig`](./env/tsconfig.md) | TypeScript project setup (per `tsconfig.json` file). |
77
86
  | [`env.node`](./env/node.md) | Modules running in NodeJS. |
78
87
  | [`env.browser`](./env/browser.md) | Modules running in browsers. |
79
88
  | [`env.react`](./env/react.md) | Modules using [React](https://react.dev/) library. |
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@open-xchange/linter-presets",
3
- "version": "0.2.0",
3
+ "version": "0.3.1",
4
4
  "description": "Configuration presets for ESLint and StyleLint",
5
5
  "repository": {
6
6
  "url": "https://gitlab.open-xchange.com/fspd/npm-packages/linter-presets"
@@ -55,19 +55,19 @@
55
55
  "eslint-plugin-vitest": "0.5.4",
56
56
  "eslint-plugin-yml": "1.14.0",
57
57
  "find-up": "7.0.0",
58
- "globals": "15.8.0",
58
+ "globals": "15.9.0",
59
59
  "picomatch": "4.0.2",
60
60
  "stylelint-config-standard": "36.0.1",
61
61
  "stylelint-config-standard-less": "3.0.1",
62
62
  "stylelint-config-standard-scss": "13.1.0",
63
63
  "stylelint-plugin-license-header": "1.0.3",
64
- "typescript-eslint": "7.18.0"
64
+ "typescript-eslint": "8.0.0"
65
65
  },
66
66
  "devDependencies": {
67
67
  "@types/confusing-browser-globals": "1.0.3",
68
68
  "@types/eslint__js": "8.42.3",
69
69
  "@types/picomatch": "3.0.0",
70
- "@typescript-eslint/utils": "7.18.0",
70
+ "@typescript-eslint/utils": "8.0.0",
71
71
  "eslint": "9.8.0",
72
72
  "husky": "9.1.4",
73
73
  "jest": "29.7.0",
@@ -1,21 +0,0 @@
1
- import type { TSESLint } from "@typescript-eslint/utils";
2
- import type { EnvBaseOptions } from "../shared/env-utils.js";
3
- /**
4
- * Configuration options for the environment preset "env.tsconfig".
5
- */
6
- export interface EnvTSConfigOptions extends EnvBaseOptions {
7
- /**
8
- * The path to the TypeScript project configuration file (`tsconfig.json`).
9
- */
10
- project: string;
11
- }
12
- /**
13
- * Creates configuration objects for TypeScript projects.
14
- *
15
- * @param envOptions
16
- * Configuration options for the environment.
17
- *
18
- * @returns
19
- * An array of configuration objects to be added to the flat configuration.
20
- */
21
- export default function tsconfig(envOptions: EnvTSConfigOptions): TSESLint.FlatConfig.ConfigArray;
@@ -1,24 +0,0 @@
1
- import { concatConfigs, createConfig, customRules } from "../shared/env-utils.js";
2
- // functions ==================================================================
3
- /**
4
- * Creates configuration objects for TypeScript projects.
5
- *
6
- * @param envOptions
7
- * Configuration options for the environment.
8
- *
9
- * @returns
10
- * An array of configuration objects to be added to the flat configuration.
11
- */
12
- export default function tsconfig(envOptions) {
13
- return concatConfigs(
14
- // path to project configuration file
15
- createConfig(envOptions, {
16
- languageOptions: {
17
- parserOptions: {
18
- project: envOptions.project,
19
- },
20
- },
21
- }),
22
- // custom rules
23
- customRules(envOptions));
24
- }
@@ -1,35 +0,0 @@
1
- # Environment `env.tsconfig`
2
-
3
- Creates configuration objects for TypeScript projects (registers a `tsconfig.json` file in the project).
4
-
5
- ## Signature
6
-
7
- ```ts
8
- function tsconfig(options: EnvTSConfigOptions): Linter.FlatConfig[]
9
- ```
10
-
11
- ## Options
12
-
13
- | Name | Type | Default | Description |
14
- | - | - | - | - |
15
- | `files` | `string[]` | _required_ | Glob patterns for source files to be included. |
16
- | `ignores` | `string[]` | `[]` | Glob patterns for source files matching `files` to be ignored. |
17
- | `project` | `string` | _required_ | The absolute path to the TypeScript project configuration file (`tsconfig.json`). |
18
- | `rules` | `Linter.RulesRecord` | `{}` | Additional linter rules to be added to the configuration. |
19
-
20
- ## Example
21
-
22
- ```js
23
- // eslint.config.js
24
- import { utils, eslint } from "@open-xchange/linter-presets"
25
-
26
- const resolve = utils.resolver(import.meta.url)
27
-
28
- export default [
29
- ...eslint.configure({ /* ... */ }),
30
- ...eslint.env.tsconfig({
31
- files: ["src/**/*.ts"],
32
- project: resolve("src/tsconfig.json"),
33
- }),
34
- ]
35
- ```