@open-xchange/linter-presets 0.1.0 → 0.1.2

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,13 @@
1
1
  # Changelog
2
2
 
3
+ ## [0.1.2] - 2024-07-12
4
+
5
+ - added: [ESLint] option `restricted.nativeDecorators`
6
+
7
+ ## [0.1.1] - 2024-07-11
8
+
9
+ - changed: [ESLint] option `stylistic.semi` as enum (always/never/off)
10
+
3
11
  ## [0.1.0] - 2024-07-10
4
12
 
5
13
  - chore: converted source code to TypeScript
package/README.md CHANGED
@@ -38,7 +38,7 @@ Usage example:
38
38
  // stylelint.config.js
39
39
  import { stylelint } from "@open-xchange/linter-presets"
40
40
 
41
- export default eslint.configure({
41
+ export default stylelint.configure({
42
42
  /* config options */
43
43
  })
44
44
  ```
@@ -78,7 +78,7 @@ export default function stylistic(options) {
78
78
  "@stylistic/quote-props": ["error", "as-needed"],
79
79
  "@stylistic/quotes": (quotes === "off") ? "off" : ["error", quotes, { avoidEscape: true }],
80
80
  "@stylistic/rest-spread-spacing": "error",
81
- "@stylistic/semi": ["error", semi ? "always" : "never"],
81
+ "@stylistic/semi": (semi === "off") ? "off" : ["error", semi],
82
82
  "@stylistic/semi-spacing": "error",
83
83
  "@stylistic/semi-style": "error",
84
84
  "@stylistic/space-before-blocks": "error",
@@ -1,23 +1,3 @@
1
- /*
2
- * @copyright Copyright (c) Open-Xchange GmbH, Germany <info@open-xchange.com>
3
- * @license AGPL-3.0
4
- *
5
- * This code is free software: you can redistribute it and/or modify
6
- * it under the terms of the GNU Affero General Public License as published by
7
- * the Free Software Foundation, either version 3 of the License, or
8
- * (at your option) any later version.
9
- *
10
- * This program is distributed in the hope that it will be useful,
11
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
12
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13
- * GNU Affero General Public License for more details.
14
- *
15
- * You should have received a copy of the GNU Affero General Public License
16
- * along with OX App Suite. If not, see <https://www.gnu.org/licenses/agpl-3.0.txt>.
17
- *
18
- * Any use of the work other than as authorized under this license or copyright law is prohibited.
19
- *
20
- */
21
1
  import noAmdModuleDirective from "../rules/no-amd-module-directive.js";
22
2
  import noInvalidModules from "../rules/no-invalid-modules.js";
23
3
  // exports ====================================================================
@@ -54,7 +54,7 @@ export function configure(options) {
54
54
  // resolve stylistic configuration options
55
55
  const stylisticOptions = {
56
56
  indent: 2,
57
- semi: false,
57
+ semi: "never",
58
58
  quotes: "single",
59
59
  dangle: "always",
60
60
  ...options?.stylistic,
@@ -1,23 +1,3 @@
1
- /*
2
- * @copyright Copyright (c) Open-Xchange GmbH, Germany <info@open-xchange.com>
3
- * @license AGPL-3.0
4
- *
5
- * This code is free software: you can redistribute it and/or modify
6
- * it under the terms of the GNU Affero General Public License as published by
7
- * the Free Software Foundation, either version 3 of the License, or
8
- * (at your option) any later version.
9
- *
10
- * This program is distributed in the hope that it will be useful,
11
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
12
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13
- * GNU Affero General Public License for more details.
14
- *
15
- * You should have received a copy of the GNU Affero General Public License
16
- * along with OX App Suite. If not, see <https://www.gnu.org/licenses/agpl-3.0.txt>.
17
- *
18
- * Any use of the work other than as authorized under this license or copyright law is prohibited.
19
- *
20
- */
21
1
  import { ESLintUtils } from "@typescript-eslint/utils";
22
2
  // exports ====================================================================
23
3
  export default ESLintUtils.RuleCreator.withoutDocs({
@@ -1,23 +1,3 @@
1
- /*
2
- * @copyright Copyright (c) Open-Xchange GmbH, Germany <info@open-xchange.com>
3
- * @license AGPL-3.0
4
- *
5
- * This code is free software: you can redistribute it and/or modify
6
- * it under the terms of the GNU Affero General Public License as published by
7
- * the Free Software Foundation, either version 3 of the License, or
8
- * (at your option) any later version.
9
- *
10
- * This program is distributed in the hope that it will be useful,
11
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
12
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13
- * GNU Affero General Public License for more details.
14
- *
15
- * You should have received a copy of the GNU Affero General Public License
16
- * along with OX App Suite. If not, see <https://www.gnu.org/licenses/agpl-3.0.txt>.
17
- *
18
- * Any use of the work other than as authorized under this license or copyright law is prohibited.
19
- *
20
- */
21
1
  import { createRequire } from "node:module";
22
2
  import { posix, dirname, extname } from "node:path";
23
3
  import { packageUpSync } from "package-up";
@@ -29,10 +29,15 @@ export interface StylisticOptions {
29
29
  */
30
30
  indent?: number;
31
31
  /**
32
- * Specifies whether to require semicolons following all statements. By
33
- * default, semicolons must be omitted if possible according to ASI rules.
32
+ * Specifies how to treat semicolons.
33
+ *
34
+ * - "always": Require semicolons following all statements.
35
+ * - "never": Require to omit semicolons according to ASI rules.
36
+ * - "off": Semicolons will not be checked.
37
+ *
38
+ * Default value is "never".
34
39
  */
35
- semi?: boolean;
40
+ semi?: "always" | "never" | "off";
36
41
  /**
37
42
  * The type of the string delimiter character. Default value is "single".
38
43
  */
@@ -115,9 +120,24 @@ export interface EnvRestrictedItems {
115
120
  export interface EnvRestrictedOverride extends EnvFilesOptions, EnvRestrictedItems {
116
121
  }
117
122
  /**
118
- * Configuration options for restricted imports and globals.
123
+ * Configuration options for banned globals, imports, properties, and syntax
124
+ * constructs in the environment.
119
125
  */
120
126
  export interface EnvRestrictedOptions extends EnvRestrictedItems {
127
+ /**
128
+ * Whether the environment supports native decorators. In this case, it
129
+ * will be required to replace TypeScript decorated `private` methods with
130
+ * native `#private` methods.
131
+ *
132
+ * Default value is `false` (TypeScript's experimental decorators cannot be
133
+ * used with native `#private` fields).
134
+ */
135
+ nativeDecorators?: boolean;
136
+ /**
137
+ * Overrides for specific subsets of files in the environment. All
138
+ * restricted items of overrides will be merged with the common restricted
139
+ * items defined for the entire environment.
140
+ */
121
141
  overrides?: EnvRestrictedOverride[];
122
142
  }
123
143
  export interface EnvRestrictedRulesResult {
@@ -1,19 +1,4 @@
1
1
  // constants ==================================================================
2
- /**
3
- * Global symbols to be banned in all source code files.
4
- */
5
- const RESTRICTED_GLOBALS = [
6
- { name: "isFinite", message: "Use 'Number.isFinite' instead." },
7
- { name: "isNaN", message: "Use 'Number.isNaN' instead." },
8
- ];
9
- /**
10
- * Syntax constructs to be banned in all source code files.
11
- */
12
- const RESTRICTED_SYNTAX = [
13
- { selector: ":matches(PropertyDefinition, MethodDefinition[kind!='constructor'])[accessibility='public']", message: "Remove 'public' keyword." },
14
- { selector: ":matches(PropertyDefinition, MethodDefinition[kind!='constructor'])[accessibility='private'][decorators.length=0]", message: "Use #private syntax instead." },
15
- { selector: "MethodDefinition[kind='constructor'] TSParameterProperty[accessibility]", message: "Use explicit class properties." },
16
- ];
17
2
  /**
18
3
  * Shared options for the core rule `no-unused-vars`, and the plugin rule
19
4
  * `@typescript-eslint/no-unused-vars`.
@@ -76,6 +61,15 @@ function createRulesRecord(generator) {
76
61
  * The generated linter rules to forbid the restricted items.
77
62
  */
78
63
  export function generateRestrictedRules(fixed, options) {
64
+ const RESTRICTED_GLOBALS = [
65
+ { name: "isFinite", message: "Use 'Number.isFinite' instead." },
66
+ { name: "isNaN", message: "Use 'Number.isNaN' instead." },
67
+ ];
68
+ const RESTRICTED_SYNTAX = [
69
+ { selector: ":matches(PropertyDefinition, MethodDefinition[kind!='constructor'])[accessibility='public']", message: "Remove 'public' keyword." },
70
+ { selector: ":matches(PropertyDefinition, MethodDefinition[kind!='constructor'])[accessibility='private']" + (options?.nativeDecorators ? "" : "[decorators.length=0]"), message: "Use #private syntax instead." },
71
+ { selector: "MethodDefinition[kind='constructor'] TSParameterProperty[accessibility]", message: "Use explicit class properties." },
72
+ ];
79
73
  // restricted items for all files in the environment
80
74
  const items = {
81
75
  globals: concatArrays(RESTRICTED_GLOBALS, fixed.globals, options?.globals),
@@ -1,23 +1,3 @@
1
- /*
2
- * @copyright Copyright (c) Open-Xchange GmbH, Germany <info@open-xchange.com>
3
- * @license AGPL-3.0
4
- *
5
- * This code is free software: you can redistribute it and/or modify
6
- * it under the terms of the GNU Affero General Public License as published by
7
- * the Free Software Foundation, either version 3 of the License, or
8
- * (at your option) any later version.
9
- *
10
- * This program is distributed in the hope that it will be useful,
11
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
12
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13
- * GNU Affero General Public License for more details.
14
- *
15
- * You should have received a copy of the GNU Affero General Public License
16
- * along with OX App Suite. If not, see <https://www.gnu.org/licenses/agpl-3.0.txt>.
17
- *
18
- * Any use of the work other than as authorized under this license or copyright law is prohibited.
19
- *
20
- */
21
1
  import { posix, sep } from "node:path";
22
2
  import { lstatSync } from "node:fs";
23
3
  import pm from "picomatch";
@@ -57,7 +57,7 @@ export default [
57
57
  ignores: ["dist/*", "external/**/*.yaml"],
58
58
  language: { ecmaVersion: 2024, sourceType: "commonjs" },
59
59
  license: resolve("./license.txt"),
60
- stylistic: { quotes: "double", semi: true },
60
+ stylistic: { quotes: "double", semi: "always" },
61
61
  }),
62
62
  ]
63
63
  ```
@@ -32,8 +32,23 @@ The option `restricted` is an object with the following properties:
32
32
  | `imports` | `EnvRestrictedName[]` | `[]` | Banned modules that must not be imported. Each entry is an object with string properties `name` and `message`. |
33
33
  | `properties` | `EnvRestrictedProperty[]` | `[]` | Banned object properties. Each entry is an object with string properties `object`, `property`, and `message`). |
34
34
  | `syntax` | `EnvRestrictedSyntax[]` | `[]` | Banned syntax constructs by [AST selectors](https://eslint.org/docs/latest/extend/selectors). Each entry is an object with string properties `selector` and `message`. |
35
+ | `nativeDecorators` | `boolean` | `false` | Whether the environment supports native decorators. In this case, it will be required to replace decorated TypeScript `private` methods with native `#private` methods (TypeScript's experimental decorators cannot be used with native `#private` fields). |
35
36
  | `overrides` | `EnvRestrictedOverride[]` | `[]` | Overrides for specific subsets of files in the environment. Each entry is an object with the common properties `files` (required) and `ignores`, and the properties `globals`, `imports`, `properties`, and `syntax` to specify restricted items (see above). All restricted items of overrides will be merged with the common restricted items defined for the entire environment. |
36
37
 
38
+ The environment `env.browser` already defines the following built-in restrictions:
39
+
40
+ | Type | Name | Description |
41
+ | - | - | - |
42
+ | Globals | [`isFinite`](https://devdocs.io/javascript/global_objects/isfinite) | Use [`Number.isFinite`](https://devdocs.io/javascript/global_objects/number/isfinite) instead. |
43
+ | | [`isNaN`](https://devdocs.io/javascript/global_objects/isnan) | Use [`Number.isNaN`](https://devdocs.io/javascript/global_objects/number/isnan) instead. |
44
+ | | [Confusing browser globals](https://github.com/facebook/create-react-app/tree/main/packages/confusing-browser-globals) | Globals such as `name` and `event` should not be used to catch typos in function parameters etc. |
45
+ | Properties | [`Object.hasOwn`](https://devdocs.io/javascript/global_objects/object/hasown) | Not yet supported by all browsers. |
46
+ | Syntax | TypeScript `public` class field modifier | Can be omitted (except for constructors of classes deriving from a class with protected constructor). |
47
+ | | TypeScript `private` class field modifier | Use native `#private` class fields. |
48
+ | | [TypeScript parameter properties](https://www.typescriptlang.org/docs/handbook/2/classes.html#parameter-properties) | Use explicit class properties. |
49
+ | | [Static class initialization blocks](https://www.typescriptlang.org/docs/handbook/2/classes.html#static-blocks-in-classes) | Not yet supported by all browsers. |
50
+ | | Module exports of [TypeScript const enumerations](https://devdocs.io/typescript~5.1/enums#enums-at-compile-time) | Not compatible with bundlers running in isolated modules mode (ESBuild). |
51
+
37
52
  ## Example
38
53
 
39
54
  ```js
@@ -25,6 +25,16 @@ function node(options: EnvNodeOptions): Linter.FlatConfig[]
25
25
 
26
26
  This option allows to specify banned globals, imports, object properties, and syntax constructs. See [documentation in `env.browser`](./browser.md#option-restricted) for a detailed description.
27
27
 
28
+ The environment `env.node` already defines the following built-in restrictions:
29
+
30
+ | Type | Name | Description |
31
+ | - | - | - |
32
+ | Globals | [`isFinite`](https://devdocs.io/javascript/global_objects/isfinite) | Use [`Number.isFinite`](https://devdocs.io/javascript/global_objects/number/isfinite) instead. |
33
+ | | [`isNaN`](https://devdocs.io/javascript/global_objects/isnan) | Use [`Number.isNaN`](https://devdocs.io/javascript/global_objects/number/isnan) instead. |
34
+ | Syntax | TypeScript `public` class field modifier | Can be omitted (except for constructors of classes deriving from a class with protected constructor). |
35
+ | | TypeScript `private` class field modifier | Use native `#private` class fields. |
36
+ | | [TypeScript parameter properties](https://www.typescriptlang.org/docs/handbook/2/classes.html#parameter-properties) | Use explicit class properties. |
37
+
28
38
  ## Example
29
39
 
30
40
  ```js
package/package.json CHANGED
@@ -1,6 +1,7 @@
1
1
  {
2
+ "$schema": "https://json.schemastore.org/package",
2
3
  "name": "@open-xchange/linter-presets",
3
- "version": "0.1.0",
4
+ "version": "0.1.2",
4
5
  "description": "Configuration presets for ESLint and StyleLint",
5
6
  "repository": {
6
7
  "url": "https://gitlab.open-xchange.com/fspd/npm-packages/linter-presets"
@@ -62,7 +63,6 @@
62
63
  "devDependencies": {
63
64
  "@types/confusing-browser-globals": "1.0.3",
64
65
  "@types/eslint__js": "8.42.3",
65
- "@types/json-schema": "7.0.15",
66
66
  "@types/picomatch": "3.0.0",
67
67
  "@typescript-eslint/utils": "7.16.0",
68
68
  "eslint": "9.6.0",
package/renovate.json ADDED
@@ -0,0 +1,10 @@
1
+ {
2
+ "$schema": "https://docs.renovatebot.com/renovate-schema.json",
3
+ "extends": [
4
+ "config:recommended"
5
+ ],
6
+ "lockFileMaintenance": {
7
+ "enabled": true
8
+ },
9
+ "configMigration": true
10
+ }