-
Notifications
You must be signed in to change notification settings - Fork 40
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add import and style sorting config + capabilities. #132
Merged
Merged
Changes from all commits
Commits
Show all changes
14 commits
Select commit
Hold shift + click to select a range
2ac3cf7
feat: style formatting with tailwind prettier plugin
ultraviolet10 d1c302c
fix: run eslint imports sort on webapp files
ultraviolet10 701f868
add eslint's `fix` to `make format` command
ultraviolet10 3a5640c
add back prettier, some other format changes
ultraviolet10 6454106
add eslint rule for grouping `src` imports
ultraviolet10 8f0427e
add missed file
ultraviolet10 8e71ee1
format `.cjs` files
ultraviolet10 eb96a28
update Makefile command
ultraviolet10 f7013b5
add `.mjs` to format rule, fix import style
ultraviolet10 5180ec4
add rule for import restrictions
ultraviolet10 3847275
update eslint rule
ultraviolet10 a48d963
fix `make` commands
ultraviolet10 e073215
fix imports
ultraviolet10 f0d780b
fix dep issues in `useScrollbox`
ultraviolet10 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
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,32 +1,65 @@ | ||
/** @type {import("eslint").Linter.Config} */ | ||
const config = { | ||
extends: ["next/core-web-vitals", "plugin:@typescript-eslint/recommended", "prettier"], | ||
parser: "@typescript-eslint/parser", | ||
parserOptions: { | ||
project: "./tsconfig.json", | ||
}, | ||
plugins: ["@typescript-eslint"], | ||
root: true, | ||
ignorePatterns: ["node_modules", "src/hooks/useScrollBox.ts"], | ||
rules: { | ||
"@typescript-eslint/no-unsafe-argument": "off", | ||
"@typescript-eslint/restrict-template-expressions": "off", | ||
"react/no-unescaped-entities": "off", | ||
"@typescript-eslint/no-empty-function": "off", | ||
"@typescript-eslint/no-explicit-any": "off", | ||
"@typescript-eslint/ban-ts-comment": "off", | ||
extends: ["next/core-web-vitals", "plugin:@typescript-eslint/recommended", "prettier"], | ||
parser: "@typescript-eslint/parser", | ||
parserOptions: { | ||
project: "./tsconfig.json", | ||
sourceType: "module", | ||
ecmaVersion: "latest", | ||
}, | ||
plugins: ["@typescript-eslint", "simple-import-sort"], | ||
root: true, | ||
ignorePatterns: ["node_modules", "src/generated.ts"], | ||
rules: { | ||
"@typescript-eslint/no-unsafe-argument": "off", | ||
"@typescript-eslint/restrict-template-expressions": "off", | ||
"react/no-unescaped-entities": "off", | ||
"@typescript-eslint/no-empty-function": "off", | ||
"@typescript-eslint/no-explicit-any": "off", | ||
"@typescript-eslint/ban-ts-comment": "off", | ||
"no-restricted-imports": "off", | ||
"@typescript-eslint/no-restricted-imports": [ | ||
"error", | ||
{ | ||
patterns: ["./*", "../*"], | ||
}, | ||
], | ||
|
||
"no-unused-vars": "off", | ||
"@typescript-eslint/no-unused-vars": [ | ||
"warn", | ||
{ | ||
// ignore unused args that start with underscore | ||
argsIgnorePattern: "^_", | ||
varsIgnorePattern: "^_", | ||
caughtErrorsIgnorePattern: "^_", | ||
}, | ||
], | ||
}, | ||
"no-unused-vars": "off", | ||
"@typescript-eslint/no-unused-vars": [ | ||
"warn", | ||
{ | ||
// ignore unused args that start with underscore | ||
argsIgnorePattern: "^_", | ||
varsIgnorePattern: "^_", | ||
caughtErrorsIgnorePattern: "^_", | ||
}, | ||
], | ||
"import/first": "error", | ||
"import/newline-after-import": "error", | ||
"import/no-duplicates": "error", | ||
"simple-import-sort/imports": [ | ||
"error", | ||
{ | ||
groups: [ | ||
// Packages. `react` related packages come first. | ||
["^react", "^next"], | ||
// External packages. | ||
["^@?\\w"], | ||
// Custom group for src/ prefixed imports | ||
["^src/"], | ||
// Parent imports. Put `..` last. | ||
["^\\.\\.(?!/?$)", "^\\.\\./?$"], | ||
// Other relative imports. Put same-folder imports and `.` last. | ||
["^\\./(?=.*/)(?!/?$)", "^\\.(?!/?$)", "^\\./?$"], | ||
// Style imports. | ||
["^.+\\.s?css$"], | ||
// Side effect imports. | ||
["^\\u0000"], | ||
], | ||
}, | ||
], | ||
}, | ||
} | ||
|
||
module.exports = 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
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,8 @@ | ||
{ | ||
"javascript.validate.enable": false, | ||
"typescript.validate.enable": false | ||
"typescript.validate.enable": false, | ||
"editor.codeActionsOnSave": { | ||
"source.fixAll.eslint": "explicit" | ||
}, | ||
"eslint.validate": ["javascript", "javascriptreact", "typescript", "typescriptreact"] | ||
} |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,8 +1,8 @@ | ||
const config = { | ||
plugins: { | ||
tailwindcss: {}, | ||
autoprefixer: {}, | ||
}, | ||
plugins: { | ||
tailwindcss: {}, | ||
autoprefixer: {}, | ||
}, | ||
} | ||
|
||
module.exports = config | ||
module.exports = 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,6 +1,6 @@ | ||
export default { | ||
plugins: { | ||
tailwindcss: {}, | ||
autoprefixer: {}, | ||
}, | ||
plugins: { | ||
tailwindcss: {}, | ||
autoprefixer: {}, | ||
}, | ||
} |
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.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
So I was confused why this would work because this is the pattern used in the link I gave to ONLY ALLOW relative links.
Turns out:
make check
does not actually run the eslint checks, it needs to bepnpm next lint --max-warnings 0
and notpnpm eslint
(but let's actually callmake lint
frommake check
, that way we avoid duplication)Even so, this should forbid every single one of our imports... turns out it does not work, probably
!
is not a thing as an operator.BUT, if you remove the
!
, then it does exactly what we want, and indeed catches a few relative imports that slipped through the cracks :)Can you fix
make check
, this file and eliminate the remaining relative imports? And also add a comment in this file to explain we forbid relative imports and absolute imports starting withsrc/
should be used instead?Oh, also you'll need to exclude
generated.ts
from eslint (ignorePatterns
option).I see we're also excluding
src/hooks/useScrollBox.ts
from linting, seems to be about ReactuseEffect
dependencies, would be good to remove it from the ignore list and either fix or simply add comments to disable eslint on thoseuseEffect
statements.