-
Notifications
You must be signed in to change notification settings - Fork 40
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
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 files in the client package. Note: The current versions of configurations require `prettier@^3`, but the `pretty-quick` command only works with `prettier@^2`. The husky git pre-commit hook needs to be updated to another package to provide the same kind of functionality (try `lint-staged`). ---- Add configs for prettier, adjust eslint rules For prettier, there are some config changes between v2 and v3. The new default for tailing commas changed causing a lot of breaks. Use the v2 default of "es5" for now. A few eslint rules changed to warnings since there are a lot of them and we don't want to fix those now. ---- Enable linting for all monorepo packages ---- Resolve lint errors for common and server packages ---- Set more eslint rules to warn to avoid mass fixes ---- Fix the current set of eslint errors A small set of changes were required for 39 total errors across a small set of files. Rather than mark those errors to the warning level and fixed in another PR, the fixes have been made here. ---- 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.