forked from konveyor/tackle2-ui
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
🌱 Setup eslint with prettier (konveyor#1291)
Replace the old and broken eslint configuration in `client/package.json` with a more robust configuration. `eslint`, `typescript-eslint` and `prettier` are configured to work together to lint javascript and typescript files. Changes: - One eslint config for all packages: `.eslintrc.cjs` - Add explicit config files for prettier: `.prettierrc.mjs`, `.prettierignore`, and `.editorconfig` - Prettier v2 and v3 have changes to some styles, including the default for tailing commas. Our configurations are now set to v2 default "es5" trailing commas. - A total of 10 eslint rules have been configurated as warnings instead of errors. There are a lot of these warnings, and fixing them in this PR would create a very large PR. Setting as warnings will allow us to fix the problems and set them back to errors in future PRs. 1 PR for each warn to error conversion is what I anticipate. - A set of errors have been fixed in the PR. These errors only hit a few times each and were easy to fix. - Use `lint-staged` as pre-commit hook: - Previously `pretty-quick` was used to run `prettier@^2` in the client package when committing staged files. Since `pretty-quick` does not currently play well with `prettier@^3`, and since we'd like to also use the eslint setup, the pre-commit hook has be changed over to use `lint-staged`. - Each monorepo package has its own `lint-staged` configuration based on the files in each repo. Both `eslint` and `prettier` are used as appropriate. If any staged files cannot be auto-fixed by eslint, the commit should fail. Signed-off-by: Scott J Dickerson <[email protected]>
- Loading branch information
Showing
30 changed files
with
2,176 additions
and
416 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
root=true | ||
|
||
[*] | ||
# standard prettier behaviors | ||
charset = utf-8 | ||
insert_final_newline = true | ||
trim_trailing_whitespace = true | ||
|
||
# Configurable prettier behaviors | ||
end_of_line = lf | ||
indent_style = space | ||
indent_size = 2 | ||
max_line_length = 80 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,90 @@ | ||
/* eslint-env node */ | ||
|
||
module.exports = { | ||
root: true, | ||
|
||
env: { | ||
browser: true, | ||
es2020: true, | ||
jest: true, | ||
}, | ||
|
||
parser: "@typescript-eslint/parser", | ||
parserOptions: { | ||
ecmaFeatures: { | ||
jsx: true, | ||
}, | ||
ecmaVersion: 2020, // keep in sync with tsconfig.json | ||
sourceType: "module", | ||
}, | ||
|
||
// eslint-disable-next-line prettier/prettier | ||
extends: [ | ||
"eslint:recommended", | ||
"plugin:@typescript-eslint/recommended", | ||
"plugin:react/recommended", | ||
"prettier", | ||
], | ||
|
||
// eslint-disable-next-line prettier/prettier | ||
plugins: [ | ||
"prettier", | ||
"unused-imports", // or eslint-plugin-import? | ||
"@typescript-eslint", | ||
"react", | ||
"react-hooks", | ||
], | ||
|
||
// NOTE: Tweak the rules as needed when bulk fixes get merged | ||
rules: { | ||
// TODO: set to "error" when prettier v2 to v3 style changes are fixed | ||
"prettier/prettier": ["warn"], | ||
|
||
// TODO: set to "error" when all resolved, but keep the `argsIgnorePattern` | ||
"@typescript-eslint/no-unused-vars": ["warn", { argsIgnorePattern: "^_" }], | ||
|
||
// TODO: each one of these can be removed or set to "error" when they're all resolved | ||
"unused-imports/no-unused-imports": ["warn"], | ||
"@typescript-eslint/ban-types": "warn", | ||
"@typescript-eslint/no-explicit-any": "warn", | ||
"react/jsx-key": "warn", | ||
"react-hooks/rules-of-hooks": "warn", | ||
"react-hooks/exhaustive-deps": "warn", | ||
"no-extra-boolean-cast": "warn", | ||
"prefer-const": "warn", | ||
|
||
// Allow the "cy-data" property for tackle-ui-test (but should really be "data-cy" w/o this rule) | ||
"react/no-unknown-property": ["error", { ignore: ["cy-data"] }], | ||
}, | ||
|
||
settings: { | ||
react: { version: "detect" }, | ||
}, | ||
|
||
ignorePatterns: [ | ||
// don't ignore dot files so config files get linted | ||
"!.*.js", | ||
"!.*.cjs", | ||
"!.*.mjs", | ||
|
||
// take the place of `.eslintignore` | ||
"dist/", | ||
"generated/", | ||
"node_modules/", | ||
], | ||
|
||
// this is a hack to make sure eslint will look at all of the file extensions we | ||
// care about without having to put it on the command line | ||
overrides: [ | ||
{ | ||
files: [ | ||
"**/*.js", | ||
"**/*.jsx", | ||
"**/*.cjs", | ||
"**/*.mjs", | ||
"**/*.ts", | ||
"**/*.tsx", | ||
], | ||
}, | ||
], | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,4 @@ | ||
#!/usr/bin/env sh | ||
. "$(dirname -- "$0")/_/husky.sh" | ||
|
||
npx pretty-quick --staged | ||
npx lint-staged |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
# Library, IDE and build locations | ||
**/node_modules/ | ||
**/coverage/ | ||
**/dist/ | ||
.vscode/ | ||
.idea/ | ||
.eslintcache/ | ||
|
||
# | ||
# NOTE: Could ignore anything that eslint will look at since eslint also applies | ||
# prettier. | ||
# |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
/** @type {import("prettier").Config} */ | ||
const config = { | ||
trailingComma: "es5", // es5 was the default in prettier v2 | ||
semi: true, | ||
singleQuote: false, | ||
|
||
// Values used from .editorconfig: | ||
// - printWidth == max_line_length | ||
// - tabWidth == indent_size | ||
// - useTabs == indent_style | ||
// - endOfLine == end_of_line | ||
}; | ||
|
||
export default config; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,3 @@ | ||
module.exports = 'test-file-stub'; | ||
/* eslint-env node */ | ||
|
||
module.exports = "test-file-stub"; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,3 @@ | ||
/* eslint-env node */ | ||
|
||
module.exports = {}; |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
/* eslint-env node */ | ||
|
||
import * as path from "path"; | ||
|
||
export const stylePaths = [ | ||
path.resolve(__dirname, "../src"), | ||
path.resolve(__dirname, "../../node_modules/patternfly"), | ||
path.resolve(__dirname, "../../node_modules/@patternfly/patternfly"), | ||
path.resolve(__dirname, "../../node_modules/@patternfly/react-styles/css"), | ||
path.resolve( | ||
__dirname, | ||
"../../node_modules/@patternfly/react-core/dist/styles/base.css" | ||
), | ||
path.resolve( | ||
__dirname, | ||
"../../node_modules/@patternfly/react-core/dist/esm/@patternfly/patternfly" | ||
), | ||
path.resolve( | ||
__dirname, | ||
"../../node_modules/@patternfly/react-core/node_modules/@patternfly/react-styles/css" | ||
), | ||
path.resolve( | ||
__dirname, | ||
"../../node_modules/@patternfly/react-table/node_modules/@patternfly/react-styles/css" | ||
), | ||
path.resolve( | ||
__dirname, | ||
"../../node_modules/@patternfly/react-inline-edit-extension/node_modules/@patternfly/react-styles/css" | ||
), | ||
]; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,5 @@ | ||
/* eslint-env node */ | ||
|
||
module.exports = { | ||
createOldCatalogs: true, // Save the \_old files | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.