@open-xchange/linter-presets 1.0.0 → 1.1.0

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,11 @@
1
1
  # Changelog
2
2
 
3
+ ## `1.1.0` – 2025-Jan-08
4
+
5
+ - add: (ESLint) plugin `eslint-plugin-depend`
6
+ - add: (ESLint) config option "packages"
7
+ - remove: (ESLint) plugin `eslint-plugin-import`
8
+
3
9
  ## `1.0.0` – 2025-Jan-03
4
10
 
5
11
  - chore: bump dependencies
@@ -0,0 +1,15 @@
1
+ import type { Linter } from "eslint";
2
+ import type { PackagesConfig } from "../shared/env-utils.js";
3
+ /**
4
+ * Defines linting rules for outdated or unneeded external dependencies.
5
+ *
6
+ * Wraps the following packages:
7
+ * - `eslint-plugin-depend`
8
+ *
9
+ * @param packagesConfig
10
+ * Resolved configuration options.
11
+ *
12
+ * @returns
13
+ * An array of configuration objects to be added to the flat configuration.
14
+ */
15
+ export default function packages(packagesConfig: PackagesConfig): Linter.Config[];
@@ -0,0 +1,28 @@
1
+ import dependPlugin from "eslint-plugin-depend";
2
+ // functions ==================================================================
3
+ /**
4
+ * Defines linting rules for outdated or unneeded external dependencies.
5
+ *
6
+ * Wraps the following packages:
7
+ * - `eslint-plugin-depend`
8
+ *
9
+ * @param packagesConfig
10
+ * Resolved configuration options.
11
+ *
12
+ * @returns
13
+ * An array of configuration objects to be added to the flat configuration.
14
+ */
15
+ export default function packages(packagesConfig) {
16
+ return [
17
+ // register rule implementations and recommended rules
18
+ dependPlugin.configs["flat/recommended"],
19
+ {
20
+ rules: {
21
+ "depend/ban-dependencies": ["error", {
22
+ modules: packagesConfig.banned,
23
+ allowed: packagesConfig.allowed,
24
+ }],
25
+ },
26
+ },
27
+ ];
28
+ }
@@ -1,5 +1,5 @@
1
1
  import type { Linter } from "eslint";
2
- import type { LanguageOptions, StylisticOptions } from "./shared/env-utils.js";
2
+ import type { LanguageOptions, PackagesOptions, StylisticOptions } from "./shared/env-utils.js";
3
3
  import node from "./env/node.js";
4
4
  import browser from "./env/browser.js";
5
5
  import jest from "./env/jest.js";
@@ -27,6 +27,10 @@ export interface ConfigureOptions {
27
27
  * Configuration options for language and project setup.
28
28
  */
29
29
  language?: LanguageOptions;
30
+ /**
31
+ * Configuration options for external package dependencies.
32
+ */
33
+ packages?: PackagesOptions;
30
34
  /**
31
35
  * Configuration options for code style.
32
36
  */
@@ -7,7 +7,7 @@ import yaml from "./config/yaml.js";
7
7
  import markdown from "./config/markdown.js";
8
8
  import license from "./config/license.js";
9
9
  import directives from "./config/directives.js";
10
- import imports from "./config/imports.js";
10
+ import packages from "./config/packages.js";
11
11
  import promises from "./config/promises.js";
12
12
  import jsdoc from "./config/jsdoc.js";
13
13
  import stylistic from "./config/stylistic.js";
@@ -62,6 +62,12 @@ export function configure(options) {
62
62
  nativeDecorators: false,
63
63
  ...options?.language,
64
64
  };
65
+ // resolve dependency configuration options
66
+ const packagesConfig = {
67
+ allowed: [],
68
+ banned: [],
69
+ ...options?.packages,
70
+ };
65
71
  // resolve stylistic configuration options
66
72
  const stylisticConfig = {
67
73
  semi: "always",
@@ -97,8 +103,8 @@ export function configure(options) {
97
103
  ...(options?.license ? license(options.license) : []),
98
104
  // default configuration for ESLint inline directives
99
105
  ...directives(),
100
- // default configuration for imports/exports
101
- ...imports(languageConfig),
106
+ // default configuration for outdated dependencies
107
+ ...packages(packagesConfig),
102
108
  // default configuration for native promises
103
109
  ...promises(),
104
110
  // default configuration for JSDoc
@@ -31,6 +31,21 @@ export interface LanguageOptions {
31
31
  nativeDecorators?: boolean;
32
32
  }
33
33
  export type LanguageConfig = DeepRequired<LanguageOptions>;
34
+ /**
35
+ * Configuration options for external package dependencies.
36
+ */
37
+ export interface PackagesOptions {
38
+ /**
39
+ * A list of packages to be allowed in the project even if they have been
40
+ * banned by the plugin `eslint-plugin-depend`.
41
+ */
42
+ allowed?: string[];
43
+ /**
44
+ * A list of additional packages to be banned in the project.
45
+ */
46
+ banned?: string[];
47
+ }
48
+ export type PackagesConfig = DeepRequired<PackagesOptions>;
34
49
  /**
35
50
  * Configuration options for code indentation.
36
51
  */
@@ -19,7 +19,7 @@ Generates standard configuration targeting the source files in the entire projec
19
19
  | Markdown files (`.md`) | [@eslint/markdown](https://github.com/eslint/markdown) |
20
20
  | License headers | [eslint-plugin-license-header](https://github.com/nikku/eslint-plugin-license-header) |
21
21
  | ESLint inline directives | [@eslint-community/eslint-plugin-eslint-comments](https://github.com/eslint-community/eslint-plugin-eslint-comments) |
22
- | Module imports | [eslint-plugin-import](https://github.com/import-js/eslint-plugin-import) |
22
+ | Outdated dependencies | [eslint-plugin-depend](https://github.com/es-tooling/eslint-plugin-depend) |
23
23
  | Native ES6 promises | [eslint-plugin-promise](https://github.com/eslint-community/eslint-plugin-promise) |
24
24
  | JSDoc source documentation | [eslint-plugin-jsdoc](https://github.com/gajus/eslint-plugin-jsdoc) |
25
25
  | Source code formatting | [@stylistic/eslint-plugin](https://eslint.style/packages/default) |
@@ -40,6 +40,9 @@ function configure(options?: ConfigureOptions): Linter.Config[]
40
40
  | `language.ecmaVersion` | `number\|"latest"` | `latest` | The ECMAScript version to be used in the project (version or year). |
41
41
  | `language.sourceType` | `"module"\|"commonjs"` | `"module"` | Specifies how to treat `.js`, `.jsx`, `.ts`, and `.tsx` files. |
42
42
  | `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. |
43
+ | `packages` | `PackagesOptions` | | Configuration options for external package dependencies. |
44
+ | `packages.allowed` | `string[]` | `[]` | Banned packages to be allowed in the project. |
45
+ | `packages.banned` | `string[]` | `[]` | Additional packages to be banned in the project. |
43
46
  | `stylistic` | `StylisticOptions` | | Configuration options for code style. |
44
47
  | `stylistic.indent` | `IndentOptions` | `{}` | Indentation size (number of space characters) per file type. |
45
48
  | `stylistic.indent.js` | `number` | `4` | JavaScript and TypeScript files (including `.jsx`, `.tsx`). |
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@open-xchange/linter-presets",
3
- "version": "1.0.0",
3
+ "version": "1.1.0",
4
4
  "description": "Configuration presets for ESLint and StyleLint",
5
5
  "repository": {
6
6
  "type": "git",
@@ -16,7 +16,7 @@
16
16
  "scripts": {
17
17
  "prepare": "yarn build",
18
18
  "prepack": "yarn build && yarn lint && yarn test",
19
- "build": "rimraf dist && tsc",
19
+ "build": "premove dist && tsc",
20
20
  "lint": "eslint .",
21
21
  "test": "cd test && eslint ."
22
22
  },
@@ -38,8 +38,8 @@
38
38
  "eslint-import-resolver-typescript": "^3.7.0",
39
39
  "eslint-plugin-chai-expect": "^3.1.0",
40
40
  "eslint-plugin-codeceptjs": "^1.3.0",
41
+ "eslint-plugin-depend": "^0.12.0",
41
42
  "eslint-plugin-eslint-plugin": "^6.4.0",
42
- "eslint-plugin-import": "^2.31.0",
43
43
  "eslint-plugin-jest": "^28.10.0",
44
44
  "eslint-plugin-jest-dom": "^5.5.0",
45
45
  "eslint-plugin-jsdoc": "^50.6.1",
@@ -72,7 +72,6 @@
72
72
  "@typescript-eslint/utils": "^8.19.0",
73
73
  "eslint": "^9.17.0",
74
74
  "jest": "^29.7.0",
75
- "rimraf": "^6.0.1",
76
75
  "stylelint": "^16.12.0",
77
76
  "typescript": "^5.7.2"
78
77
  },
@@ -1,15 +0,0 @@
1
- import type { Linter } from "eslint";
2
- import type { LanguageConfig } from "../shared/env-utils.js";
3
- /**
4
- * Adds linter rules for `import` and `export` statements.
5
- *
6
- * Wraps the following packages:
7
- * - `eslint-plugin-import`
8
- *
9
- * @param languageConfig
10
- * Resolved configuration options.
11
- *
12
- * @returns
13
- * An array of configuration objects to be added to the flat configuration.
14
- */
15
- export default function importConfig(languageConfig: LanguageConfig): Linter.Config[];
@@ -1,62 +0,0 @@
1
- import importPlugin from "eslint-plugin-import";
2
- import { fixupPluginRules } from "@eslint/compat";
3
- // exports ====================================================================
4
- /**
5
- * Adds linter rules for `import` and `export` statements.
6
- *
7
- * Wraps the following packages:
8
- * - `eslint-plugin-import`
9
- *
10
- * @param languageConfig
11
- * Resolved configuration options.
12
- *
13
- * @returns
14
- * An array of configuration objects to be added to the flat configuration.
15
- */
16
- export default function importConfig(languageConfig) {
17
- // configuration properties
18
- const { ecmaVersion, sourceType } = languageConfig;
19
- // extensions of ES module files
20
- const jsExtensions = (sourceType === "module") ? [".js", ".mjs"] : [".mjs"];
21
- const tsExtensions = (sourceType === "module") ? [".ts", ".mts"] : [".mts"];
22
- return [{
23
- files: [
24
- ...jsExtensions.map(ext => "**/*" + ext),
25
- ...tsExtensions.map(ext => "**/*" + ext),
26
- ],
27
- // register rule implementations of the plugin
28
- plugins: {
29
- import: fixupPluginRules(importPlugin), // https://github.com/import-js/eslint-plugin-import/issues/2948
30
- },
31
- // language options need to be repeated for this plugin
32
- languageOptions: {
33
- parserOptions: {
34
- ecmaVersion,
35
- sourceType: "module",
36
- },
37
- },
38
- // parser settings need to be repeated for this plugin
39
- settings: {
40
- "import/parsers": {
41
- espree: jsExtensions,
42
- "@typescript-eslint/parser": tsExtensions,
43
- },
44
- "import/resolver": {
45
- typescript: true,
46
- node: true,
47
- },
48
- },
49
- // reconfigure plugin rules
50
- rules: {
51
- // recommended rules
52
- ...importPlugin.flatConfigs.recommended.rules,
53
- ...importPlugin.flatConfigs.typescript.rules,
54
- // change or disable a few recommended rules
55
- "import/default": "off",
56
- "import/no-duplicates": "error",
57
- "import/no-named-as-default": "off",
58
- "import/no-named-as-default-member": "off",
59
- "import/no-unresolved": "off",
60
- },
61
- }];
62
- }