@open-xchange/linter-presets 0.0.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.
Files changed (40) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +39 -0
  3. package/doc/eslint.md +343 -0
  4. package/doc/stylelint.md +3 -0
  5. package/doc/utils.md +30 -0
  6. package/lib/eslint/config/base.js +136 -0
  7. package/lib/eslint/config/directives.js +21 -0
  8. package/lib/eslint/config/js.js +36 -0
  9. package/lib/eslint/config/jsdoc.js +55 -0
  10. package/lib/eslint/config/json.js +37 -0
  11. package/lib/eslint/config/license.js +33 -0
  12. package/lib/eslint/config/promises.js +33 -0
  13. package/lib/eslint/config/stylistic.js +123 -0
  14. package/lib/eslint/config/ts.js +100 -0
  15. package/lib/eslint/config/yaml.js +34 -0
  16. package/lib/eslint/env/browser.d.ts +13 -0
  17. package/lib/eslint/env/browser.js +127 -0
  18. package/lib/eslint/env/codecept.d.ts +13 -0
  19. package/lib/eslint/env/codecept.js +70 -0
  20. package/lib/eslint/env/jest.d.ts +13 -0
  21. package/lib/eslint/env/jest.js +56 -0
  22. package/lib/eslint/env/node.d.ts +21 -0
  23. package/lib/eslint/env/node.js +59 -0
  24. package/lib/eslint/env/plugin.d.ts +13 -0
  25. package/lib/eslint/env/plugin.js +61 -0
  26. package/lib/eslint/env/react.d.ts +19 -0
  27. package/lib/eslint/env/react.js +103 -0
  28. package/lib/eslint/env/tsconfig.d.ts +19 -0
  29. package/lib/eslint/env/tsconfig.js +37 -0
  30. package/lib/eslint/env/vitest.d.ts +13 -0
  31. package/lib/eslint/env/vitest.js +103 -0
  32. package/lib/eslint/index.d.ts +90 -0
  33. package/lib/eslint/index.js +106 -0
  34. package/lib/eslint/shared/constants.js +33 -0
  35. package/lib/eslint/shared/types.d.ts +90 -0
  36. package/lib/index.d.ts +3 -0
  37. package/lib/index.js +3 -0
  38. package/lib/utils/index.d.ts +4 -0
  39. package/lib/utils/index.js +18 -0
  40. package/package.json +61 -0
@@ -0,0 +1,106 @@
1
+
2
+ import base from "./config/base.js";
3
+ import js from "./config/js.js";
4
+ import ts from "./config/ts.js";
5
+ import json from "./config/json.js";
6
+ import yaml from "./config/yaml.js";
7
+ import license from "./config/license.js";
8
+ import directives from "./config/directives.js";
9
+ import promises from "./config/promises.js";
10
+ import jsdoc from "./config/jsdoc.js";
11
+ import stylistic from "./config/stylistic.js";
12
+
13
+ import tsconfig from "./env/tsconfig.js";
14
+ import node from "./env/node.js";
15
+ import browser from "./env/browser.js";
16
+ import jest from "./env/jest.js";
17
+ import vitest from "./env/vitest.js";
18
+ import codecept from "./env/codecept.js";
19
+ import react from "./env/react.js";
20
+ import plugin from "./env/plugin.js";
21
+
22
+ // environment presets ========================================================
23
+
24
+ /**
25
+ * A collection with all available environment presets.
26
+ */
27
+ export const env = {
28
+ tsconfig,
29
+ node,
30
+ browser,
31
+ jest,
32
+ vitest,
33
+ codecept,
34
+ react,
35
+ plugin,
36
+ };
37
+
38
+ // functions ==================================================================
39
+
40
+ /**
41
+ * Generates standard configuration objects targeting the source files in the
42
+ * entire project.
43
+ *
44
+ * @param {import("./shared/types.js").ESLintPresetsOptions} [options]
45
+ * Plugin configuration options.
46
+ *
47
+ * @returns {import("./shared/types.js").FlatConfigArray}
48
+ * An array of configuration objects to be added to the flat configuration.
49
+ */
50
+ export function configure(options) {
51
+
52
+ // resolve language configuration options
53
+ const languageConfig = {
54
+ ecmaVersion: 2022,
55
+ sourceType: "module",
56
+ ...options?.language,
57
+ };
58
+
59
+ // resolve stylistic configuration options
60
+ const stylisticConfig = {
61
+ indent: 2,
62
+ semi: false,
63
+ quotes: "single",
64
+ dangle: "always",
65
+ ...options?.stylistic,
66
+ };
67
+
68
+ return [
69
+
70
+ // ignore certain files and folders
71
+ ...(options?.ignores?.length ? [{ ignores: options.ignores }] : []),
72
+
73
+ // module types and standard rules for all JS/TS source files
74
+ ...base(languageConfig),
75
+
76
+ // default configuration for JavaScript files
77
+ ...js(),
78
+
79
+ // default configuration for TypeScript files
80
+ ...ts(),
81
+
82
+ // default configuration for JSON files
83
+ ...json(stylisticConfig),
84
+
85
+ // default configuration for YAML files
86
+ ...yaml(stylisticConfig),
87
+
88
+ // check for correct license headers
89
+ ...(options?.license ? license(options.license) : []),
90
+
91
+ // default configuration for ESLint inline directives
92
+ ...directives(),
93
+
94
+ // default configuration for native promises
95
+ ...promises(),
96
+
97
+ // default configuration for JSDoc
98
+ ...jsdoc(),
99
+
100
+ // default configuration for code style checks
101
+ ...stylistic(stylisticConfig),
102
+
103
+ // custom rules
104
+ ...(options?.rules ? [{ rules: options.rules }] : []),
105
+ ];
106
+ }
@@ -0,0 +1,33 @@
1
+
2
+ // constants ==================================================================
3
+
4
+ /**
5
+ * Shared options for the core rule `no-unused-vars`, and the plugin rule
6
+ * `@typescript-eslint/no-unused-vars`.
7
+ */
8
+ export const NO_UNUSED_VARS_OPTIONS = {
9
+ varsIgnorePattern: "^_",
10
+ argsIgnorePattern: "^_",
11
+ destructuredArrayIgnorePattern: "^_",
12
+ caughtErrors: "all",
13
+ ignoreRestSiblings: true,
14
+ };
15
+
16
+ /**
17
+ * Global symbols to be banned in all source code files, to be used in the core
18
+ * rule "no-restricted-globals".
19
+ */
20
+ export const RESTRICTED_GLOBALS = [
21
+ { name: "isFinite", message: "Use 'Number.isFinite' instead." },
22
+ { name: "isNaN", message: "Use 'Number.isNaN' instead." },
23
+ ];
24
+
25
+ /**
26
+ * Syntax constructs to be banned in all source code files, to be used in the
27
+ * core rule "no-restricted-syntax".
28
+ */
29
+ export const RESTRICTED_SYNTAX = [
30
+ { selector: ":matches(PropertyDefinition, MethodDefinition[kind!='constructor'])[accessibility='public']", message: "Remove 'public' keyword." },
31
+ { selector: ":matches(PropertyDefinition, MethodDefinition[kind!='constructor'])[accessibility='private']", message: "Use #private syntax instead." },
32
+ { selector: "MethodDefinition[kind='constructor'] TSParameterProperty[accessibility]", message: "Use explicit class properties." },
33
+ ];
@@ -0,0 +1,90 @@
1
+
2
+ import { Linter } from "eslint";
3
+
4
+ // types ======================================================================
5
+
6
+ /**
7
+ * An array of ESLint configuration entries in flat-config format.
8
+ */
9
+ export type FlatConfigArray = Linter.FlatConfig[];
10
+
11
+ /**
12
+ * Configuration options for language and project setup.
13
+ */
14
+ export interface LanguageOptions {
15
+
16
+ /**
17
+ * The ECMAScript version to be used in the project (version or year).
18
+ * Default value is `2022`.
19
+ */
20
+ ecmaVersion?: number;
21
+
22
+ /**
23
+ * Specifies how to treat `.js`, `.jsx`, `.ts`, and `.tsx` files.
24
+ *
25
+ * - "module": The files will be considered being ES modules.
26
+ * - "commonjs": The files will be considered being CommonJS modules.
27
+ *
28
+ * Default value is "module".
29
+ */
30
+ sourceType?: "module" | "commonjs";
31
+ }
32
+
33
+ /**
34
+ * Configuration options for code style.
35
+ */
36
+ export interface StylisticOptions {
37
+
38
+ /**
39
+ * Default indentation size (number of space characters). Will be applied
40
+ * to JavaScript, TypeScript, JSON, and YAML files, as well as JSX markup.
41
+ * Default value is `2`.
42
+ */
43
+ indent?: number;
44
+
45
+ /**
46
+ * Specifies whether to require semicolons following all statements. By
47
+ * default, semicolons must be omitted if possible according to ASI rules.
48
+ */
49
+ semi?: boolean;
50
+
51
+ /**
52
+ * The type of the string delimiter character. Default value is "single".
53
+ */
54
+ quotes?: "single" | "double" | "off";
55
+
56
+ /**
57
+ * Specifies how to treat dangling commas in multiline lists.
58
+ *
59
+ * - "always": Dangling commas will be required in all multi-line array
60
+ * literals, object literals, function parameters, template parameters,
61
+ * imports, and exports.
62
+ * - "never": Dangling commas will be forbidden.
63
+ * - "off": Dangling commas will not be checked.
64
+ *
65
+ * Default value is "always".
66
+ */
67
+ dangle?: "always" | "never" | "off";
68
+ }
69
+
70
+ /**
71
+ * Shared options for an environment preset: include and exclude files, and add
72
+ * more linter rules.
73
+ */
74
+ export interface EnvBaseOptions {
75
+
76
+ /**
77
+ * Glob patterns for source files to be included into the environment.
78
+ */
79
+ files: readonly string[];
80
+
81
+ /**
82
+ * Glob patterns for source files matching `files` to be ignored.
83
+ */
84
+ ignores?: readonly string[];
85
+
86
+ /**
87
+ * Additional linter rules to be added to the configuration.
88
+ */
89
+ rules?: Linter.RulesRecord;
90
+ }
package/lib/index.d.ts ADDED
@@ -0,0 +1,3 @@
1
+
2
+ export * as utils from "./utils/index";
3
+ export * as eslint from "./eslint/index";
package/lib/index.js ADDED
@@ -0,0 +1,3 @@
1
+
2
+ export * as utils from "./utils/index.js";
3
+ export * as eslint from "./eslint/index.js";
@@ -0,0 +1,4 @@
1
+
2
+ // functions ==================================================================
3
+
4
+ export function resolver(url: string): (file: string) => string;
@@ -0,0 +1,18 @@
1
+
2
+ import { URL, fileURLToPath } from "node:url";
3
+
4
+ // functions ==================================================================
5
+
6
+ /**
7
+ * Creates and returns a resolver function for file paths relative to the given
8
+ * base URL of a script file.
9
+ *
10
+ * @param {string} url
11
+ * The base URL of the calling script, usually `import.meta.url`.
12
+ *
13
+ * @returns {(file: string) => string}
14
+ * A function that converts relative file paths to absolute file paths.
15
+ */
16
+ export function resolver(url) {
17
+ return file => fileURLToPath(new URL(file, url));
18
+ }
package/package.json ADDED
@@ -0,0 +1,61 @@
1
+ {
2
+ "name": "@open-xchange/linter-presets",
3
+ "version": "0.0.1",
4
+ "description": "Configuration presets for ESLint and StyleLint",
5
+ "repository": "https://gitlab.open-xchange.com/fspd/npm-packages/linter-presets",
6
+ "license": "MIT",
7
+ "engines": {
8
+ "node": ">=18"
9
+ },
10
+ "packageManager": "yarn@4.3.1",
11
+ "type": "module",
12
+ "exports": "./lib/index.js",
13
+ "scripts": {
14
+ "prepare": "husky",
15
+ "lint": "eslint ."
16
+ },
17
+ "lint-staged": {
18
+ "*.{js,ts,json}": "yarn lint"
19
+ },
20
+ "dependencies": {
21
+ "@eslint-community/eslint-plugin-eslint-comments": "4.3.0",
22
+ "@eslint/compat": "1.1.0",
23
+ "@eslint/js": "9.6.0",
24
+ "@stylistic/eslint-plugin": "2.3.0",
25
+ "@stylistic/eslint-plugin-migrate": "2.3.0",
26
+ "confusing-browser-globals": "1.0.11",
27
+ "eslint-plugin-chai-expect": "3.1.0",
28
+ "eslint-plugin-codeceptjs": "1.3.0",
29
+ "eslint-plugin-eslint-plugin": "6.2.0",
30
+ "eslint-plugin-jest": "28.6.0",
31
+ "eslint-plugin-jest-dom": "5.4.0",
32
+ "eslint-plugin-jsdoc": "48.5.0",
33
+ "eslint-plugin-jsonc": "2.16.0",
34
+ "eslint-plugin-jsx-a11y": "6.9.0",
35
+ "eslint-plugin-jsx-expressions": "1.3.2",
36
+ "eslint-plugin-license-header": "0.6.1",
37
+ "eslint-plugin-n": "17.9.0",
38
+ "eslint-plugin-promise": "6.4.0",
39
+ "eslint-plugin-react": "7.34.3",
40
+ "eslint-plugin-react-hooks": "4.6.2",
41
+ "eslint-plugin-react-hooks-static-deps": "1.0.7",
42
+ "eslint-plugin-react-refresh": "0.4.7",
43
+ "eslint-plugin-testing-library": "6.2.2",
44
+ "eslint-plugin-vitest": "0.5.4",
45
+ "eslint-plugin-yml": "1.14.0",
46
+ "globals": "15.8.0",
47
+ "typescript-eslint": "7.15.0"
48
+ },
49
+ "devDependencies": {
50
+ "eslint": "9.6.0",
51
+ "husky": "9.0.11",
52
+ "typescript": "5.5.3"
53
+ },
54
+ "peerDependencies": {
55
+ "eslint": "^9.6.0",
56
+ "typescript": "^5.5.3"
57
+ },
58
+ "resolutions": {
59
+ "semver": "^7.6.2"
60
+ }
61
+ }