Skip to content

Commit

Permalink
feat!: publish all rules we want to enforce (#48)
Browse files Browse the repository at this point in the history
* feat!: publish all rules we want to enforce as warning
* feat!: add curly and ban-types
* feat!: list used rules in readme

fix #23 #40 #41 #42 #49
  • Loading branch information
alhugot-azpn authored Dec 17, 2021
1 parent c2f5676 commit e19f6db
Show file tree
Hide file tree
Showing 8 changed files with 1,454 additions and 47 deletions.
76 changes: 37 additions & 39 deletions .eslintrc.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,7 @@

// https://eslint.org/docs/developer-guide/shareable-configs#publishing-a-shareable-config
module.exports = {
// https://github.com/typescript-eslint/typescript-eslint/blob/master/packages/parser/README.md
// No need to define @typescript-eslint/parser as the react-app config specifies
// it as an override for all ts and tsx files, otherwise babel-eslint is used.
// parser: "@typescript-eslint/parser",
parser: "@typescript-eslint/parser",
parserOptions: {
ecmaVersion: 6,
sourceType: "module",
Expand Down Expand Up @@ -62,48 +59,49 @@ module.exports = {
//************************************************************************
// Enforced
//
curly: "warn",
// Set console calls to emit warnings as not enabled by eslint:recommended
"no-console": "error",
"no-console": "warn",
// Increase react-hooks/exhaustive-deps from warning to error
"react-hooks/exhaustive-deps": "error",
// //************************************************************************
// // Relaxed: rules we are progressively adopting
// //
// // enforce types
// "@typescript-eslint/no-explicit-any": "warn",
// // enforce typed exports
// "@typescript-eslint/explicit-module-boundary-types": "warn",
// // enforce clean code
// "@typescript-eslint/no-unused-vars": "warn",
// // enforce interface naming convention
"react-hooks/exhaustive-deps": "warn",
// enforce types
"@typescript-eslint/no-explicit-any": "warn",
// Bans specific types from being used (e.g. builtin types)
"@typescript-eslint/ban-types": "warn",
// enforce typed exports
"@typescript-eslint/explicit-module-boundary-types": "warn",
// enforce clean code
"@typescript-eslint/no-unused-vars": "warn",
// Keep naming convention for later
// enforce interface naming convention
// "@typescript-eslint/naming-convention": [
// "warn",
// {
// "selector": "interface",
// "format": ["PascalCase"],
// "custom": {
// "regex": "^I[A-Z]",
// "match": true
// }
// selector: "interface",
// format: ["PascalCase"],
// custom: {
// regex: "^I[A-Z]",
// match: true,
// },
// },
// {
// "selector": "typeAlias",
// "format": ["PascalCase"],
// "custom": {
// "regex": "^T[A-Z]",
// "match": true
// }
// }
// ],
// // enforce import ordering
// "sort-imports": [
// "warn",
// {
// "allowSeparatedGroups": true,
// "memberSyntaxSortOrder": ["none", "all", "single", "multiple"],
// "ignoreCase": false
// }
// selector: "typeAlias",
// format: ["PascalCase"],
// custom: {
// regex: "^T[A-Z]",
// match: true,
// },
// },
// ],
// enforce import ordering
"sort-imports": [
"warn",
{
allowSeparatedGroups: true,
memberSyntaxSortOrder: ["none", "all", "single", "multiple"],
ignoreCase: false,
},
],
},
overrides: [
// Typescript overrides
Expand Down Expand Up @@ -141,7 +139,7 @@ module.exports = {
// > 10 chars and contains a separator "." so it would have to follow the no-duplicate-string rule
"sonarjs/no-duplicate-string": "off",
//Default complexity is 15 but since cypress test have some before and after hooks, let's increase a little bit
"sonarjs/cognitive-complexity": ["error", 20],
"sonarjs/cognitive-complexity": ["warn", 20],
},
},
],
Expand Down
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,5 @@
node_modules/
# Ignore local build
emerson-eps-eslint-config-*.tgz
# tsc
tmp
18 changes: 18 additions & 0 deletions .prettierignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
# Use .gitignore syntax

# Generated/third-party code
tmp/
node_modules/

# IDE Config
.vscode/
.idea/

# tooling
.scannerwork/

# Generated files
config.json

# npm can rewrite the whole package.json file with some commands
package.json
18 changes: 11 additions & 7 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ This is the home of the shared E&P Software ESLint configs. The default config s

## Usage

The ESLint config and Prettier config must both be added to get the full shared configuration. The ESLint configuration includes the prettier plugin which will load the prettier config and report issues as errors.
The ESLint config and Prettier config must both be added to get the full shared configuration.

### (1) Install the shared Prettier and ESLint configs

Expand All @@ -26,12 +26,12 @@ npm install --save-dev prettier eslint

### (2) Configure Prettier

Add `@emerson-eps/prettier-config` to your `package.json`:
Add `@emerson-eps/prettier-config` to your `.prettierrc.js`:

```json
{
"prettier": "@emerson-eps/prettier-config"
}
```js
module.exports = {
...require("@emerson-eps/prettier-config"),
};
```

For more advanced setups, including how to override settings, see the instructions in the [@emerson-eps/prettier-config](https://github.com/emerson-eps/prettier-config) repository.
Expand All @@ -49,14 +49,18 @@ Specify the package in the [`extends`](http://eslint.org/docs/user-guide/configu
}
```

### List of current rules

The list of applied rules can be found [here](./config.json)

## Running ESLint on your code

Add a lint script to your `package.json`, for example:

```json
{
"scripts": {
"lint": "eslint ."
"lint": "eslint . --max-warnings=0"
}
}
```
Expand Down
Loading

0 comments on commit e19f6db

Please sign in to comment.