@boehringer-ingelheim/eslint-config 1.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/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2023 Boehringer Ingelheim
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md ADDED
@@ -0,0 +1,193 @@
1
+ # ESLint Configuration
2
+
3
+ > ESLint statically analyzes your code to quickly find problems. It is built into most text editors and you can run ESLint as part of your continuous integration pipeline. - <https://eslint.org/>
4
+
5
+ This is the shared ESLint configuration used at [Boehringer Ingelheim](https://github.com/orgs/Boehringer-Ingelheim) for code styling.
6
+
7
+ [![npm version](https://img.shields.io/npm/v/@boehringer-ingelheim/eslint-config?style=for-the-badge)](https://www.npmjs.com/package/@boehringer-ingelheim/eslint-config)
8
+ [![npm downloads](https://img.shields.io/npm/dm/@boehringer-ingelheim/eslint-config?style=for-the-badge)](https://www.npmjs.com/package/@boehringer-ingelheim/eslint-config)
9
+ [![License: Apache-2.0](https://img.shields.io/badge/License-MIT-green.svg?style=for-the-badge)](https://github.com/boehringer-ingelheim/eslint-config/blob/master/LICENSE)
10
+ [![Maintenance](https://img.shields.io/badge/Maintained%3F-yes-green.svg?style=for-the-badge)](https://github.com/boehringer-ingelheim/eslint-config/graphs/commit-activity)
11
+ [![Conventional Commits](https://img.shields.io/badge/Conventional%20Commits-1.0.0-green.svg?logo=conventional-commits&style=for-the-badge)](https://conventionalcommits.org)
12
+ [![semantic-release: angular](https://img.shields.io/badge/semantic--release-angular-494949?logo=semantic-release&style=for-the-badge)](https://github.com/semantic-release/semantic-release)
13
+
14
+ ## Usage
15
+
16
+ ### Install the package
17
+
18
+ ```sh
19
+ npm install --save-dev @boehringer-ingelheim/eslint-config
20
+ ```
21
+
22
+ ### Add the configuration
23
+
24
+ Create or update the `.eslintrc.js` file in your projects root directory accordingly.
25
+
26
+ ```js
27
+ module.exports = {
28
+ extends: ["@boehringer-ingelheim/eslint-config/base/strict"],
29
+ };
30
+ ```
31
+
32
+ #### Extend or Override configuration
33
+
34
+ This is not recommended as the goal is to have similar code stylings in all projects, but if for some reason you need to add or change the configuration, it is possible in the following way:
35
+
36
+ ```js
37
+ module.exports = {
38
+ extends: ["@boehringer-ingelheim/eslint-config/base/strict"],
39
+ rules: {
40
+ "no-empty-function": "off",
41
+ },
42
+ };
43
+ ```
44
+
45
+ More Information: [ESLint - Configuration Files
46
+ ](https://eslint.org/docs/latest/use/configure/configuration-files#extending-configuration-files)
47
+
48
+ ### Run
49
+
50
+ ```sh
51
+ npx eslint .
52
+ ```
53
+
54
+ ## Shared Configurations
55
+
56
+ Opinionated Options that differ from the standard/recommended eslint configurations.
57
+
58
+ ### `@boehringer-ingelheim/eslint-config/base`
59
+
60
+ ```js
61
+ module.exports = {
62
+ extends: ["@boehringer-ingelheim/eslint-config/base"],
63
+ };
64
+ ```
65
+
66
+ This shared ESLint configuration is set up for TypeScript projects that adhere to modern JavaScript standards. It uses the latest version of TypeScript (ES2022) and extends several plugins and recommended rules to enforce best practices and catch potential errors.
67
+
68
+ The following plugins are used in this configuration:
69
+
70
+ - [`@typescript-eslint/eslint-plugin`](https://typescript-eslint.io/rules/)
71
+ - [`eslint-plugin-import`](https://github.com/import-js/eslint-plugin-import)
72
+ - [`eslint-plugin-sonarjs`](https://github.com/SonarSource/eslint-plugin-sonarjs)
73
+
74
+ Additionally, the [`eslint-plugin-sort-keys-plus`](https://github.com/forivall/eslint-plugin-sort-keys-plus) is used to automatically fix sorting issues.
75
+
76
+ This configuration also sets up the TypeScript parser [`@typescript-eslint/parser`](https://typescript-eslint.io/architecture/parser) and [`eslint-import-resolver-typescript`](https://github.com/import-js/eslint-import-resolver-typescript). The TypeScript project file `./tsconfig.json` is set as default value for the project option in the parser configuration. If this is not the case, this must be changed accordingly:
77
+
78
+ ```js
79
+ module.exports = {
80
+ parserOptions: {
81
+ // Use `tsconfing.dev.json` as typescript project configuration, see: https://typescript-eslint.io/architecture/parser/#project
82
+ project: "./tsconfig.dev.json",
83
+ },
84
+ };
85
+ ```
86
+
87
+ ### `@boehringer-ingelheim/eslint-config/base/strict`
88
+
89
+ ```js
90
+ module.exports = {
91
+ extends: ["@boehringer-ingelheim/eslint-config/base/strict"],
92
+ };
93
+ ```
94
+
95
+ This shared ESLint configuration extends the `@boehringer-ingelheim/eslint-config/base` configuration and adds additional strict linting rules from the `@typescript-eslint/eslint-plugin` plugin. These strict rules aim to enforce a high standard of code quality and improve code maintainability.
96
+
97
+ ### `@boehringer-ingelheim/eslint-config/react`
98
+
99
+ ```js
100
+ module.exports = {
101
+ extends: ["@boehringer-ingelheim/eslint-config/base/strict", "@boehringer-ingelheim/eslint-config/react"],
102
+ };
103
+ ```
104
+
105
+ This shared ESLint configuration is specifically tailored for [React](https://reactjs.org/) projects, and extends `@boehringer-ingelheim/eslint-config/base`. It uses the browser environment, and includes recommended configurations for the following plugins: jsx-a11y, react, and react-hooks.
106
+
107
+ - [`eslint-plugin-jsx-a11y`](https://github.com/jsx-eslint/eslint-plugin-jsx-a11y)
108
+ - [`eslint-plugin-react`](https://github.com/jsx-eslint/eslint-plugin-react)
109
+ - [`eslint-plugin-react-hooks`](https://github.com/facebook/react/tree/main/packages/eslint-plugin-react-hooks)
110
+
111
+ The configuration sets several custom rules, including `@typescript-eslint/ban-types` and `@typescript-eslint/consistent-type-definitions`, as well as rules for organizing and formatting import statements.
112
+
113
+ ### `@boehringer-ingelheim/eslint-config/playwright`
114
+
115
+ ```js
116
+ module.exports = {
117
+ extends: ["@boehringer-ingelheim/eslint-config/base/strict", "@boehringer-ingelheim/eslint-config/playwright"],
118
+ };
119
+ ```
120
+
121
+ This shared ESLint configuration is designed to enforce best practices and recommendations when writing tests with Playwright. It extends the [`eslint-plugin-playwright`](https://github.com/playwright-community/eslint-plugin-playwright) configuration and adds the following rules:
122
+
123
+ - [`playwright/prefer-to-be`](https://github.com/playwright-community/eslint-plugin-playwright/blob/main/docs/rules/prefer-to-be.md): enforces the use of `.toBe()` instead of `.toEqual()` when testing for equality.
124
+ - [`playwright/prefer-to-have-length`](https://github.com/playwright-community/eslint-plugin-playwright/blob/main/docs/rules/prefer-to-have-length.md): enforces the use of `.toHaveLength()` instead of `.toEqual(n)` when testing the length of an object.
125
+ - [`playwright/require-top-level-describe`](https://github.com/playwright-community/eslint-plugin-playwright/blob/main/docs/rules/require-top-level-describe.md): requires tests to be organized into top-level `describe()` blocks.
126
+
127
+ ## Local Development
128
+
129
+ ### Install Dependencies
130
+
131
+ ```sh
132
+ npm install
133
+ ```
134
+
135
+ ### Test
136
+
137
+ ```sh
138
+ npm test
139
+ ```
140
+
141
+ ### Repair
142
+
143
+ This command may be useful when obscure errors or issues are encountered. It removes and recreates dependencies of your project.
144
+
145
+ ```sh
146
+ npm run repair
147
+ ```
148
+
149
+ ### Release
150
+
151
+ Fully automated version management and package publishing via [semantic-release](https://github.com/semantic-release). It bumps the version according to conventional commits, publishes the package to npm and release a new version to GitHub.
152
+
153
+ #### Automatic Release (GitHub Action) [Recommended]
154
+
155
+ Make sure that the secrets `GITHUB_TOKEN` and `NPM_TOKEN` are available in GitHub repository.
156
+
157
+ ```sh
158
+ npm run release:ci
159
+ ```
160
+
161
+ #### Manual Release
162
+
163
+ Make sure that the environment variables `GITHUB_TOKEN` and `NPM_TOKEN` are set or declared in `.env` and a productive build was previously created via `npm run build`.
164
+
165
+ ```sh
166
+ npm run release
167
+ ```
168
+
169
+ ## Roadmap
170
+
171
+ - [ ] Shared configuration: Angular
172
+ - [ ] Shared configuration: Node.js
173
+ - [ ] Test Cases
174
+ - [ ] "[Flat](https://eslint.org/docs/latest/use/configure/configuration-files-new)" Config
175
+
176
+ ## Show your support
177
+
178
+ Give a ⭐️ if this project helped you!
179
+
180
+ ## License
181
+
182
+ Copyright © 2023 [Boehringer Ingelheim](https://github.com/boehringer-ingelheim).<br />
183
+ This project is [MIT](https://github.com/boehringer-ingelheim/eslint-config/blob/master/LICENSE) licensed.
184
+
185
+ ## Resources
186
+
187
+ - <https://eslint.org/>
188
+ - <https://typescript-eslint.io/>
189
+ - <https://react-typescript-cheatsheet.netlify.app/>
190
+ - <https://prettier.io/>
191
+ - <https://conventionalcommits.org/en/v1.0.0/>
192
+ - <https://semantic-release.gitbook.io/>
193
+ - <https://semver.org/>
package/base/index.js ADDED
@@ -0,0 +1,106 @@
1
+ /**
2
+ * Workaround to allow ESLint to resolve plugins that were installed
3
+ * by an external config, see https://github.com/eslint/eslint/issues/3458.
4
+ */
5
+ require("@rushstack/eslint-patch/modern-module-resolution");
6
+
7
+ /** @type {import('eslint').ESLint.ConfigData & { parserOptions: import('eslint').ESLint.ConfigData & import('@typescript-eslint/parser').ParserOptions } } */
8
+ module.exports = {
9
+ env: {
10
+ es2022: true,
11
+ },
12
+ extends: [
13
+ "eslint:recommended",
14
+ "plugin:@typescript-eslint/recommended",
15
+ "plugin:@typescript-eslint/recommended-requiring-type-checking",
16
+ "plugin:import/recommended",
17
+ "plugin:import/typescript",
18
+ "plugin:sonarjs/recommended",
19
+ ],
20
+ parser: "@typescript-eslint/parser",
21
+ parserOptions: {
22
+ project: "./tsconfig.json",
23
+ },
24
+ plugins: ["@typescript-eslint", "sonarjs", "sort-keys-plus"],
25
+ rules: {
26
+ // @typescript-eslint: https://github.com/typescript-eslint/typescript-eslint/tree/main/packages/eslint-plugin/docs/rules
27
+ "@typescript-eslint/no-floating-promises": ["error", { ignoreVoid: true }],
28
+ "@typescript-eslint/no-misused-promises": [
29
+ "error",
30
+ {
31
+ checksVoidReturn: false,
32
+ },
33
+ ],
34
+ "@typescript-eslint/no-unused-vars": [
35
+ "error",
36
+ {
37
+ argsIgnorePattern: "^_",
38
+ caughtErrorsIgnorePattern: "^_",
39
+ varsIgnorePattern: "^_",
40
+ },
41
+ ],
42
+ "@typescript-eslint/sort-type-constituents": "error",
43
+
44
+ // eslint: https://github.com/eslint/eslint/tree/main/lib/rules
45
+ "arrow-body-style": ["error", "as-needed"],
46
+ camelcase: "warn",
47
+ curly: "error",
48
+ "default-case": "error",
49
+ "dot-notation": ["error", { allowPattern: "^[a-z]+(_[a-z]+)+$" }],
50
+ eqeqeq: "error",
51
+ "logical-assignment-operators": ["error", "never"],
52
+ "no-console": ["warn", { allow: ["warn", "error"] }],
53
+ "no-else-return": ["error", { allowElseIf: false }],
54
+ "no-empty-function": "error",
55
+ "no-lonely-if": "error",
56
+ "no-negated-condition": "error",
57
+ "no-nested-ternary": "error",
58
+ "no-plusplus": ["error", { allowForLoopAfterthoughts: true }],
59
+ "no-unneeded-ternary": "error",
60
+ "no-useless-concat": "error",
61
+ "operator-assignment": ["error", "never"],
62
+ "prefer-const": "error",
63
+ "prefer-rest-params": "error",
64
+ "prefer-template": "error",
65
+
66
+ // eslint-plugin-import: https://github.com/import-js/eslint-plugin-import/tree/main/docs/rules
67
+ "import/no-cycle": "error",
68
+ "import/no-unused-modules": [
69
+ "error",
70
+ {
71
+ missingExports: true,
72
+ src: ["."],
73
+ unusedExports: true,
74
+ },
75
+ ],
76
+ "import/order": [
77
+ "error",
78
+ {
79
+ alphabetize: {
80
+ caseInsensitive: true,
81
+ order: "asc",
82
+ orderImportKind: "asc",
83
+ },
84
+ },
85
+ ],
86
+ "import/prefer-default-export": "off",
87
+
88
+ /**
89
+ * Required to fix sort-keys automatically, since this is not done by default.
90
+ * See: https://github.com/forivall/eslint-plugin-sort-keys-plus
91
+ */
92
+ "sort-keys-plus/sort-keys": [
93
+ "error",
94
+ "asc",
95
+ {
96
+ caseSensitive: false,
97
+ natural: true,
98
+ },
99
+ ],
100
+ },
101
+ settings: {
102
+ "import/resolver": {
103
+ typescript: true,
104
+ },
105
+ },
106
+ };
package/base/strict.js ADDED
@@ -0,0 +1,10 @@
1
+ /**
2
+ * Workaround to allow ESLint to resolve plugins that were installed
3
+ * by an external config, see https://github.com/eslint/eslint/issues/3458.
4
+ */
5
+ require("@rushstack/eslint-patch/modern-module-resolution");
6
+
7
+ /** @type {import('eslint').ESLint.ConfigData} */
8
+ module.exports = {
9
+ extends: ["./index.js", "plugin:@typescript-eslint/strict"],
10
+ };
package/package.json ADDED
@@ -0,0 +1,56 @@
1
+ {
2
+ "name": "@boehringer-ingelheim/eslint-config",
3
+ "version": "1.0.0",
4
+ "description": "Shared eslint configuration used at Boehringer Ingelheim for code styling",
5
+ "keywords": [
6
+ "boehringer",
7
+ "boehringer-ingelheim",
8
+ "config",
9
+ "configuration",
10
+ "eslint",
11
+ "eslintrc",
12
+ "eslint-config",
13
+ "linter"
14
+ ],
15
+ "license": "MIT",
16
+ "files": [
17
+ "base",
18
+ "react",
19
+ "playwright"
20
+ ],
21
+ "main": "base/index.js",
22
+ "scripts": {
23
+ "prepare": "husky install && chmod ug+x .husky/*",
24
+ "release": "dotenv -- semantic-release --no-ci",
25
+ "release:ci": "semantic-release",
26
+ "repair": "npx --no rimraf .git/hooks node_modules package-lock.json && npm install"
27
+ },
28
+ "peerDependencies": {
29
+ "eslint": "8"
30
+ },
31
+ "dependencies": {
32
+ "@rushstack/eslint-patch": "1.2.0",
33
+ "@typescript-eslint/eslint-plugin": "5.51.0",
34
+ "@typescript-eslint/parser": "5.51.0",
35
+ "eslint-import-resolver-typescript": "3.5.3",
36
+ "eslint-plugin-import": "2.27.5",
37
+ "eslint-plugin-jsx-a11y": "6.7.1",
38
+ "eslint-plugin-playwright": "0.12.0",
39
+ "eslint-plugin-react": "7.32.2",
40
+ "eslint-plugin-react-hooks": "4.6.0",
41
+ "eslint-plugin-sonarjs": "0.18.0",
42
+ "eslint-plugin-sort-keys-plus": "1.3.1"
43
+ },
44
+ "devDependencies": {
45
+ "@boehringer-ingelheim/prettier-config": "1.0.0",
46
+ "@commitlint/cli": "17.4.2",
47
+ "@commitlint/config-conventional": "17.4.2",
48
+ "@commitlint/types": "17.4.0",
49
+ "@semantic-release/changelog": "6.0.2",
50
+ "@semantic-release/git": "10.0.1",
51
+ "dotenv-cli": "7.0.0",
52
+ "husky": "8.0.3",
53
+ "prettier": "2.8.3",
54
+ "semantic-release": "20.1.0"
55
+ }
56
+ }
@@ -0,0 +1,16 @@
1
+ /**
2
+ * Workaround to allow ESLint to resolve plugins that were installed
3
+ * by an external config, see https://github.com/eslint/eslint/issues/3458.
4
+ */
5
+ require("@rushstack/eslint-patch/modern-module-resolution");
6
+
7
+ /** @type {import('eslint').ESLint.ConfigData} */
8
+ module.exports = {
9
+ extends: ["plugin:playwright/playwright-test"],
10
+ rules: {
11
+ // eslint-plugin-playwright: https://github.com/playwright-community/eslint-plugin-playwright
12
+ "playwright/prefer-to-be": "error",
13
+ "playwright/prefer-to-have-length": "error",
14
+ "playwright/require-top-level-describe": "error",
15
+ },
16
+ };
package/react/index.js ADDED
@@ -0,0 +1,84 @@
1
+ /**
2
+ * Workaround to allow ESLint to resolve plugins that were installed
3
+ * by an external config, see https://github.com/eslint/eslint/issues/3458.
4
+ */
5
+ require("@rushstack/eslint-patch/modern-module-resolution");
6
+
7
+ /** @type {import('eslint').ESLint.ConfigData & { parserOptions: import('eslint').ESLint.ConfigData & import('@typescript-eslint/parser').ParserOptions } } */
8
+ module.exports = {
9
+ env: {
10
+ browser: true,
11
+ },
12
+ extends: ["../base/index.js", "plugin:jsx-a11y/recommended", "plugin:react/recommended", "plugin:react/jsx-runtime"],
13
+ parserOptions: {
14
+ ecmaFeatures: {
15
+ jsx: true,
16
+ },
17
+ ecmaVersion: "latest",
18
+ sourceType: "module",
19
+ },
20
+ plugins: ["jsx-a11y", "react", "react-hooks"],
21
+ rules: {
22
+ // @typescript-eslint: https://github.com/typescript-eslint/typescript-eslint/tree/main/packages/eslint-plugin/docs/rules
23
+ "@typescript-eslint/ban-types": [
24
+ "error",
25
+ {
26
+ types: {
27
+ "React.FC": {
28
+ message:
29
+ "Please use object type destructure declaration, see: https://react-typescript-cheatsheet.netlify.app/docs/basic/getting-started/function_components",
30
+ },
31
+ "React.FunctionalComponent": {
32
+ message:
33
+ "Please use object type destructure declaration, see: https://react-typescript-cheatsheet.netlify.app/docs/basic/getting-started/function_components",
34
+ },
35
+ },
36
+ },
37
+ ],
38
+ "@typescript-eslint/consistent-type-definitions": ["error", "type"],
39
+
40
+ // eslint-plugin-import: https://github.com/import-js/eslint-plugin-import/tree/main/docs/rules
41
+ "import/order": [
42
+ "error",
43
+ {
44
+ alphabetize: {
45
+ caseInsensitive: true,
46
+ order: "asc",
47
+ orderImportKind: "asc",
48
+ },
49
+ pathGroups: [
50
+ {
51
+ group: "external",
52
+ pattern: "react",
53
+ position: "before",
54
+ },
55
+ ],
56
+ pathGroupsExcludedImportTypes: ["react"],
57
+ },
58
+ ],
59
+
60
+ // eslint-plugin-react: https://github.com/jsx-eslint/eslint-plugin-react/tree/master/lib/rules
61
+ "react/jsx-pascal-case": "error",
62
+ "react/jsx-sort-props": [
63
+ "error",
64
+ {
65
+ callbacksLast: true,
66
+ ignoreCase: true,
67
+ noSortAlphabetically: false,
68
+ reservedFirst: true,
69
+ shorthandFirst: false,
70
+ shorthandLast: false,
71
+ },
72
+ ],
73
+ "react/sort-default-props": "error",
74
+
75
+ // eslint-plugin-react-hooks: https://github.com/facebook/react/blob/main/packages/eslint-plugin-react-hooks/README.md
76
+ "react-hooks/exhaustive-deps": "error",
77
+ "react-hooks/rules-of-hooks": "error",
78
+ },
79
+ settings: {
80
+ react: {
81
+ version: "detect",
82
+ },
83
+ },
84
+ };