@clipboard-health/eslint-config 0.0.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/README.md ADDED
@@ -0,0 +1,42 @@
1
+ # @clipboard-health/eslint-config
2
+
3
+ Shared [ESLint](https://eslint.org/) configuration.
4
+
5
+ ## Table of Contents
6
+
7
+ - [Install](#install)
8
+ - [Local development commands](#local-development-commands)
9
+
10
+ ## Install
11
+
12
+ ```bash
13
+ npm install -D @clipboard-health/eslint-config eslint-config-prettier prettier
14
+ ```
15
+
16
+ Then, modify your `.eslintrc.js` file:
17
+
18
+ ```js
19
+ module.exports = {
20
+ extends: ["@clipboard-health", "prettier"],
21
+ overrides: [
22
+ {
23
+ files: ["*.ts", "*.tsx", "*.js", "*.jsx"],
24
+ parserOptions: {
25
+ project: "tsconfig.lint.json",
26
+ tsconfigRootDir: __dirname,
27
+ },
28
+ },
29
+ {
30
+ files: ["*.spec.ts", "*.spec.tsx", "*.spec.js", "*.spec.jsx"],
31
+ env: {
32
+ jest: true,
33
+ },
34
+ },
35
+ ],
36
+ root: true,
37
+ };
38
+ ```
39
+
40
+ ## Local development commands
41
+
42
+ See [`package.json`](./package.json) `scripts` for a list of commands.
package/package.json ADDED
@@ -0,0 +1,44 @@
1
+ {
2
+ "name": "@clipboard-health/eslint-config",
3
+ "description": "Clipboard Health's ESLint configuration.",
4
+ "version": "0.0.0",
5
+ "bugs": "https://github.com/clipboardhealth/core-utils/issues",
6
+ "keywords": [
7
+ "config",
8
+ "eslint"
9
+ ],
10
+ "license": "MIT",
11
+ "main": "./src/index.js",
12
+ "peerDependencies": {
13
+ "@typescript-eslint/eslint-plugin": "^7",
14
+ "@typescript-eslint/parser": "^7",
15
+ "eslint": "^8",
16
+ "eslint-config-airbnb-base": "^15",
17
+ "eslint-config-prettier": "^9",
18
+ "eslint-config-xo": "^0.45",
19
+ "eslint-config-xo-react": "^0.27",
20
+ "eslint-config-xo-typescript": "^1",
21
+ "eslint-plugin-eslint-comments": "^3",
22
+ "eslint-plugin-import": "^2",
23
+ "eslint-plugin-jest": "^27.7",
24
+ "eslint-plugin-n": "^16",
25
+ "eslint-plugin-no-only-tests": "^3",
26
+ "eslint-plugin-no-use-extend-native": "^0.5",
27
+ "eslint-plugin-react": "^7",
28
+ "eslint-plugin-security": "^1",
29
+ "eslint-plugin-simple-import-sort": "^10",
30
+ "eslint-plugin-sonarjs": "^0.23",
31
+ "eslint-plugin-unicorn": "^48"
32
+ },
33
+ "publishConfig": {
34
+ "access": "public"
35
+ },
36
+ "repository": {
37
+ "type": "git",
38
+ "url": "git+https://github.com/clipboardhealth/core-utils.git",
39
+ "directory": "packages/nx-plugin"
40
+ },
41
+ "type": "commonjs",
42
+ "typings": "./src/index.d.ts",
43
+ "types": "./src/index.d.ts"
44
+ }
package/src/index.d.ts ADDED
@@ -0,0 +1,92 @@
1
+ declare let _extends: string[];
2
+ export { _extends as extends };
3
+ export declare let parser: string;
4
+ export declare namespace parserOptions {
5
+ let project: string[];
6
+ let tsconfigRootDir: string;
7
+ }
8
+ export declare let plugins: string[];
9
+ export declare let rules: {
10
+ /**
11
+ * Disable the capitalization of comments
12
+ * It makes code "not build" when just commented temporarily, which we've
13
+ * found to add more friction than the value from having consistent capitalization.
14
+ */
15
+ "capitalized-comments": string;
16
+ "@typescript-eslint/consistent-type-definitions": string[];
17
+ "@typescript-eslint/naming-convention": string;
18
+ "security/detect-object-injection": string;
19
+ "@typescript-eslint/no-unused-vars": (string | {
20
+ argsIgnorePattern: string;
21
+ })[];
22
+ "no-return-await": string;
23
+ "@typescript-eslint/return-await": string[];
24
+ curly: string[];
25
+ "class-methods-use-this": string;
26
+ "import/extensions": string;
27
+ "n/no-missing-import": string;
28
+ "n/no-unpublished-import": string;
29
+ "unicorn/prefer-module": string;
30
+ "import/no-extraneous-dependencies": string;
31
+ "import/no-unresolved": string;
32
+ "import/prefer-default-export": string;
33
+ "new-cap": (string | {
34
+ newIsCap: boolean;
35
+ capIsNew: boolean;
36
+ })[];
37
+ "import/no-cycle": (string | {
38
+ ignoreExternal: boolean;
39
+ maxDepth: number;
40
+ })[];
41
+ "no-only-tests/no-only-tests": string;
42
+ "no-restricted-syntax": (string | {
43
+ selector: string;
44
+ message: string;
45
+ })[];
46
+ "no-shadow": string;
47
+ "object-shorthand": string[];
48
+ "simple-import-sort/imports": string;
49
+ "simple-import-sort/exports": string;
50
+ "unicorn/no-array-for-each": string;
51
+ "unicorn/no-array-reduce": string;
52
+ "unicorn/prevent-abbreviations": (string | {
53
+ ignore: RegExp[];
54
+ })[];
55
+ "no-underscore-dangle": string;
56
+ "no-use-before-define": (string | {
57
+ functions: boolean;
58
+ classes: boolean;
59
+ })[];
60
+ "no-restricted-imports": (string | {
61
+ paths: {
62
+ name: string;
63
+ importNames: string[];
64
+ message: string;
65
+ }[];
66
+ })[];
67
+ };
68
+ export declare let overrides: ({
69
+ files: string[];
70
+ rules: {
71
+ "@typescript-eslint/no-unsafe-assignment": string;
72
+ "sonarjs/no-duplicate-string": string;
73
+ "@typescript-eslint/ban-types"?: never;
74
+ };
75
+ } | {
76
+ files: string[];
77
+ rules: {
78
+ "@typescript-eslint/ban-types": (string | {
79
+ extendDefaults: boolean;
80
+ types: {
81
+ null: boolean;
82
+ };
83
+ })[];
84
+ "@typescript-eslint/no-unsafe-assignment"?: never;
85
+ "sonarjs/no-duplicate-string"?: never;
86
+ };
87
+ })[];
88
+ export declare namespace settings {
89
+ namespace node {
90
+ let version: string;
91
+ }
92
+ }
package/src/index.js ADDED
@@ -0,0 +1,161 @@
1
+ "use strict";
2
+ module.exports = {
3
+ extends: [
4
+ "eslint:recommended",
5
+ "plugin:@typescript-eslint/eslint-recommended",
6
+ "plugin:@typescript-eslint/recommended",
7
+ "airbnb-base",
8
+ "plugin:eslint-comments/recommended",
9
+ "plugin:jest/recommended",
10
+ "plugin:jest/style",
11
+ "plugin:import/recommended",
12
+ "plugin:n/recommended",
13
+ "plugin:no-use-extend-native/recommended",
14
+ "plugin:security/recommended",
15
+ "plugin:sonarjs/recommended",
16
+ "plugin:unicorn/recommended",
17
+ "xo",
18
+ "xo-typescript/space",
19
+ "prettier",
20
+ ],
21
+ parser: "@typescript-eslint/parser",
22
+ parserOptions: {
23
+ project: ["tsconfig.json"],
24
+ tsconfigRootDir: __dirname,
25
+ },
26
+ plugins: ["jest", "no-only-tests", "simple-import-sort", "sonarjs", "@typescript-eslint"],
27
+ rules: {
28
+ /**
29
+ * Disable the capitalization of comments
30
+ * It makes code "not build" when just commented temporarily, which we've
31
+ * found to add more friction than the value from having consistent capitalization.
32
+ */
33
+ "capitalized-comments": "off",
34
+ // See https://github.com/microsoft/TypeScript/wiki/Performance#preferring-interfaces-over-intersections
35
+ "@typescript-eslint/consistent-type-definitions": ["error", "interface"],
36
+ // Too many false positives
37
+ "@typescript-eslint/naming-convention": "off",
38
+ "security/detect-object-injection": "off",
39
+ // Prefer an escape hatch instead of an outright ban
40
+ "@typescript-eslint/no-unused-vars": ["warn", { argsIgnorePattern: "^_" }],
41
+ // Prefer debugging ease over an extra microtask by requiring `return await`.
42
+ // `no-return-await` states "This can make debugging more difficult."
43
+ "no-return-await": "off",
44
+ "@typescript-eslint/return-await": ["error", "always"],
45
+ // Prevent bugs
46
+ curly: ["error", "all"],
47
+ // Recommends using static fields instead of moving to a function
48
+ "class-methods-use-this": "off",
49
+ // Our libraries don't use ESM
50
+ "import/extensions": "off",
51
+ "n/no-missing-import": "off",
52
+ "n/no-unpublished-import": "off",
53
+ "unicorn/prefer-module": "off",
54
+ // Rely on `"n/no-extraneous-import"` instead
55
+ "import/no-extraneous-dependencies": "off",
56
+ // Doesn't play well with NX/monorepos
57
+ "import/no-unresolved": "off",
58
+ // Prefer named exports
59
+ "import/prefer-default-export": "off",
60
+ // Allow PascalCase for Decorators
61
+ "new-cap": ["warn", { newIsCap: true, capIsNew: false }],
62
+ "import/no-cycle": ["error", { ignoreExternal: true, maxDepth: 16 }],
63
+ /*
64
+ * Don't allow `.only` in tests to prevent it from making it
65
+ * into `main` and circumventing our tests.
66
+ */
67
+ "no-only-tests/no-only-tests": "error",
68
+ // Adapter from Airbnb's config, but allows ForOfStatement.
69
+ // See https://github.com/airbnb/javascript/blob/0f3ca32323b8d5770de3301036e65511c6d18e00/packages/eslint-config-airbnb-base/rules/style.js#L340-L358
70
+ "no-restricted-syntax": [
71
+ "error",
72
+ {
73
+ selector: "ForInStatement",
74
+ message: "for..in loops iterate over the entire prototype chain, which is virtually never what you want. Use Object.{keys,values,entries}, and iterate over the resulting array.",
75
+ },
76
+ {
77
+ selector: "LabeledStatement",
78
+ message: "Labels are a form of GOTO; using them makes code confusing and hard to maintain and understand.",
79
+ },
80
+ {
81
+ selector: "WithStatement",
82
+ message: "`with` is disallowed in strict mode because it makes code impossible to predict and optimize.",
83
+ },
84
+ ],
85
+ // False positive on `enum`s
86
+ "no-shadow": "off",
87
+ /*
88
+ * Only enable for properties. Favor arrow functions, they don’t have a `this` reference,
89
+ * preventing accidental usage.
90
+ */
91
+ "object-shorthand": ["error", "properties"],
92
+ // Sort imports and exports
93
+ "simple-import-sort/imports": "warn",
94
+ "simple-import-sort/exports": "warn",
95
+ // "Better readability" is subjective
96
+ "unicorn/no-array-for-each": "off",
97
+ "unicorn/no-array-reduce": "off",
98
+ // Allow common, well understood abbreviations
99
+ "unicorn/prevent-abbreviations": [
100
+ "error",
101
+ { ignore: [/config/i, /params/i, /props/i, /ref/i] },
102
+ ],
103
+ // Polarizing naming convention that isn't followed by us
104
+ "no-underscore-dangle": "off",
105
+ // We use TypeScript where these are caught by the compiler
106
+ "no-use-before-define": ["error", { functions: false, classes: false }],
107
+ "no-restricted-imports": [
108
+ "error",
109
+ {
110
+ paths: [
111
+ // We want `ObjectId` to be imported from `mongoose` only
112
+ {
113
+ name: "mongodb",
114
+ importNames: ["ObjectId", "ObjectID"],
115
+ message: 'Importing `ObjectId` from `mongodb` is not allowed. Use `import { Types } from "mongoose"` and then `Types.ObjectId` instead.',
116
+ },
117
+ ],
118
+ },
119
+ ],
120
+ },
121
+ overrides: [
122
+ {
123
+ files: [
124
+ "*.spec.ts",
125
+ "*.spec.tsx",
126
+ "*.spec.js",
127
+ "*.spec.jsx",
128
+ "*.test.ts",
129
+ "*.test.tsx",
130
+ "*.test.js",
131
+ "*.test.jsx",
132
+ ],
133
+ rules: {
134
+ // Interferes with `jest`'s `expect.any`
135
+ "@typescript-eslint/no-unsafe-assignment": "off",
136
+ // Duplication allows verbose test case setups and asserts
137
+ "sonarjs/no-duplicate-string": "off",
138
+ },
139
+ },
140
+ /**
141
+ * Exclude *.dto.ts, null is needed for PATCH endpoints to differentiate empty from optional fields
142
+ * Exclude *.repository.ts, null is needed for our ORMs (prisma and mongoose)
143
+ */
144
+ {
145
+ files: ["**/*.dto.ts", "**/*.repository.ts"],
146
+ rules: {
147
+ "@typescript-eslint/ban-types": [
148
+ "error",
149
+ {
150
+ extendDefaults: true,
151
+ types: {
152
+ null: false,
153
+ },
154
+ },
155
+ ],
156
+ },
157
+ },
158
+ ],
159
+ settings: { node: { version: ">=18.15.0" } },
160
+ };
161
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../../../packages/eslint-config/src/index.js"],"names":[],"mappings":";AAAA,MAAM,CAAC,OAAO,GAAG;IACf,OAAO,EAAE;QACP,oBAAoB;QACpB,8CAA8C;QAC9C,uCAAuC;QACvC,aAAa;QACb,oCAAoC;QACpC,yBAAyB;QACzB,mBAAmB;QACnB,2BAA2B;QAC3B,sBAAsB;QACtB,yCAAyC;QACzC,6BAA6B;QAC7B,4BAA4B;QAC5B,4BAA4B;QAC5B,IAAI;QACJ,qBAAqB;QACrB,UAAU;KACX;IACD,MAAM,EAAE,2BAA2B;IACnC,aAAa,EAAE;QACb,OAAO,EAAE,CAAC,eAAe,CAAC;QAC1B,eAAe,EAAE,SAAS;KAC3B;IACD,OAAO,EAAE,CAAC,MAAM,EAAE,eAAe,EAAE,oBAAoB,E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K,EAAE;4BACL,IAAI,EAAE,KAAK;yBACZ;qBACF;iBACF;aACF;SACF;KACF;IACD,QAAQ,EAAE,EAAE,IAAI,EAAE,EAAE,OAAO,EAAE,WAAW,EAAE,EAAE;CAC7C,CAAC"}
package/src/react.d.ts ADDED
@@ -0,0 +1,6 @@
1
+ declare let _extends: string[];
2
+ export { _extends as extends };
3
+ export declare namespace parserOptions {
4
+ let project: string[];
5
+ let tsconfigRootDir: string;
6
+ }
package/src/react.js ADDED
@@ -0,0 +1,9 @@
1
+ "use strict";
2
+ module.exports = {
3
+ extends: ["./index", "xo-react/space"],
4
+ parserOptions: {
5
+ project: ["tsconfig.json"],
6
+ tsconfigRootDir: __dirname,
7
+ },
8
+ };
9
+ //# sourceMappingURL=react.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"react.js","sourceRoot":"","sources":["../../../../packages/eslint-config/src/react.js"],"names":[],"mappings":";AAAA,MAAM,CAAC,OAAO,GAAG;IACf,OAAO,EAAE,CAAC,SAAS,EAAE,gBAAgB,CAAC;IACtC,aAAa,EAAE;QACb,OAAO,EAAE,CAAC,eAAe,CAAC;QAC1B,eAAe,EAAE,SAAS;KAC3B;CACF,CAAC"}