-
Notifications
You must be signed in to change notification settings - Fork 2
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 eslint-config package #168
Merged
Merged
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
bc782da
feat(eslint-config): Add package
wormat c797ead
refactor(pool-math): Use eslint-config package
wormat b35bc93
chore(solana-types): Use @swim-io/eslint-config package
wormat 6df3758
chore(solana-usdc-usdt-swap): Use @swim-io/eslint-config package
wormat 3173e68
style(solana-usdc-usdt-swap): Fix lint
wormat 5058f53
chore(eslint-config): Add GitHub workflow
wormat File filter
Filter by extension
Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
name: "Verify eslint-config build" | ||
on: | ||
pull_request: | ||
paths: | ||
- "packages/eslint-config/**.ts" | ||
- "packages/eslint-config/**.json" | ||
push: | ||
branches: | ||
- master | ||
|
||
jobs: | ||
verify: | ||
runs-on: ubuntu-latest | ||
|
||
defaults: | ||
run: | ||
working-directory: ./packages/eslint-config | ||
|
||
steps: | ||
- uses: actions/checkout@v2 | ||
- uses: actions/setup-node@v2 | ||
with: | ||
node-version: 16 | ||
cache: "yarn" | ||
- name: Install dependencies | ||
run: yarn install --immutable | ||
- name: Check format | ||
run: yarn format:check | ||
- name: Check lint | ||
run: yarn lint --max-warnings=0 |
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 |
---|---|---|
|
@@ -5,6 +5,7 @@ module.exports = { | |
2, | ||
"always", | ||
[ | ||
"eslint-config", | ||
"pool-deployment", | ||
"pool-math", | ||
"pool-playground", | ||
|
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,11 @@ | ||
{ | ||
"extends": ["@swim-io/eslint-config/js-only"], | ||
"env": { | ||
"node": true | ||
}, | ||
"rules": { | ||
"functional/immutable-data": "off", | ||
"import/no-commonjs": "off", | ||
"import/unambiguous": "off" | ||
} | ||
} |
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,2 @@ | ||
build/ | ||
types/ |
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,41 @@ | ||
# ESLint config | ||
|
||
Shared default ESLint configuration for Swim TS projects. | ||
|
||
## Installation | ||
|
||
Install the package: | ||
|
||
```sh | ||
npm install --save-dev @swim-io/eslint-config | ||
``` | ||
|
||
Install the required peer dependencies: | ||
|
||
```sh | ||
npm install --save-dev eslint eslint-config-prettier eslint-plugin-functional eslint-plugin-import eslint-plugin-jest eslint-plugin-prettier | ||
``` | ||
|
||
For TS projects also install these optional dependencies: | ||
nicomiicro marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
```sh | ||
npm install --save-dev @typescript-eslint/eslint-plugin @typescript-eslint/parser eslint-plugin-deprecation | ||
``` | ||
|
||
## Usage | ||
|
||
In TS projects extend from the default config in your ESLint configuration file: | ||
|
||
```json | ||
{ | ||
"extends": ["@swim-io"] | ||
} | ||
``` | ||
|
||
In JS projects extend from the JS-only config: | ||
|
||
```json | ||
{ | ||
"extends": ["@swim-io/eslint-config/js-only"] | ||
} | ||
``` |
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,45 @@ | ||
module.exports = { | ||
plugins: ["@typescript-eslint", "deprecation"], | ||
extends: [ | ||
"@swim-io/eslint-config/js-only", | ||
"plugin:@typescript-eslint/recommended", | ||
"plugin:@typescript-eslint/recommended-requiring-type-checking", | ||
"plugin:import/typescript", | ||
], | ||
parser: "@typescript-eslint/parser", | ||
parserOptions: { | ||
project: "./tsconfig.json", | ||
}, | ||
rules: { | ||
// @typescript-eslint | ||
"@typescript-eslint/consistent-type-imports": "error", | ||
"@typescript-eslint/explicit-module-boundary-types": "off", | ||
"@typescript-eslint/member-ordering": "error", | ||
"@typescript-eslint/no-empty-function": "off", | ||
"@typescript-eslint/no-explicit-any": "off", | ||
"@typescript-eslint/no-floating-promises": "error", | ||
"@typescript-eslint/no-unnecessary-condition": "error", | ||
"@typescript-eslint/no-unnecessary-type-assertion": "error", | ||
"@typescript-eslint/no-unsafe-call": "off", | ||
"@typescript-eslint/no-unsafe-return": "off", | ||
"@typescript-eslint/no-shadow": "error", | ||
"@typescript-eslint/prefer-readonly-parameter-types": "off", | ||
|
||
// deprecation | ||
"deprecation/deprecation": "warn", | ||
}, | ||
overrides: [ | ||
{ | ||
files: ["**/*.test.ts"], | ||
env: { | ||
node: true, | ||
}, | ||
rules: { | ||
"@typescript-eslint/no-unsafe-argument": "off", | ||
"@typescript-eslint/no-unsafe-call": "off", | ||
"@typescript-eslint/no-unsafe-member-access": "off", | ||
"@typescript-eslint/no-unsafe-return": "off", | ||
}, | ||
}, | ||
], | ||
}; |
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,47 @@ | ||
module.exports = { | ||
root: true, | ||
plugins: ["functional", "import", "jest", "prettier"], | ||
extends: [ | ||
"eslint:recommended", | ||
"prettier", | ||
"plugin:prettier/recommended", | ||
"plugin:import/recommended", | ||
"plugin:functional/external-recommended", | ||
"plugin:functional/no-mutations", | ||
"plugin:jest/recommended", | ||
], | ||
env: { | ||
"jest/globals": true, | ||
}, | ||
rules: { | ||
// Vanilla ESLint | ||
"no-console": ["warn", { allow: ["error", "info", "table", "warn"] }], | ||
"no-undef": "error", | ||
"sort-imports": ["error", { ignoreDeclarationSort: true }], | ||
|
||
// functional | ||
"functional/immutable-data": ["error", { ignorePattern: "this" }], | ||
"functional/no-let": "off", | ||
"functional/prefer-readonly-type": ["error", { ignoreClass: "fieldsOnly" }], | ||
|
||
// import | ||
"import/extensions": ["error", "always", { ts: "never", tsx: "never" }], | ||
"import/first": "error", | ||
"import/newline-after-import": "error", | ||
"import/no-absolute-path": "error", | ||
"import/no-amd": "error", | ||
"import/no-commonjs": "error", | ||
"import/no-cycle": "error", | ||
"import/no-deprecated": "error", | ||
"import/no-dynamic-require": "error", | ||
"import/no-mutable-exports": "error", | ||
"import/no-self-import": "error", | ||
"import/no-unused-modules": "error", | ||
"import/no-useless-path-segments": "error", | ||
"import/order": [ | ||
"error", | ||
{ alphabetize: { order: "asc" }, "newlines-between": "always" }, | ||
], | ||
"import/unambiguous": "error", | ||
}, | ||
}; |
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,51 @@ | ||
{ | ||
"name": "@swim-io/eslint-config", | ||
"version": "0.2.0", | ||
"description": "Shared default ESLint configuration for Swim TS projects.", | ||
"main": "index.js", | ||
"files": [ | ||
"*.js", | ||
"*.md" | ||
], | ||
"repository": { | ||
"type": "git", | ||
"url": "https://github.com/swim-io/swim/tree/master/packages/eslint-config" | ||
}, | ||
"publishConfig": { | ||
"access": "public", | ||
"registry": "https://registry.npmjs.org" | ||
}, | ||
"scripts": { | ||
"format": "prettier --write \"*.js\"", | ||
"format:check": "prettier --check index.js", | ||
"lint": "eslint \"./*.js\"", | ||
"lint:fix": "eslint --fix \"./*.js\"", | ||
"test": "echo \"Error: no test specified\" && exit 1", | ||
"verify": "yarn format:check && yarn lint", | ||
"prepare": "yarn verify" | ||
}, | ||
"peerDependencies": { | ||
"eslint": ">= 8.19", | ||
"eslint-config-prettier": "^8.5", | ||
"eslint-plugin-functional": "^4.2", | ||
"eslint-plugin-import": "^2.26", | ||
"eslint-plugin-jest": "^26.5", | ||
"eslint-plugin-prettier": "^4.2" | ||
}, | ||
"optionalDependencies": { | ||
"@typescript-eslint/eslint-plugin": "^5.30", | ||
"@typescript-eslint/parser": "^5.30", | ||
"eslint-plugin-deprecation": "^1.3" | ||
}, | ||
"devDependencies": { | ||
"eslint": "^8.19.0", | ||
"eslint-config-prettier": "^8.5", | ||
"eslint-plugin-deprecation": "^1.3.2", | ||
"eslint-plugin-functional": "^4.2.1", | ||
"eslint-plugin-import": "^2.26.0", | ||
"eslint-plugin-jest": "^26.5.3", | ||
"eslint-plugin-prettier": "^4.2.1", | ||
"jest": "^28.1.2", | ||
"prettier": "^2.7.1" | ||
} | ||
} |
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,81 +1,3 @@ | ||
{ | ||
"root": true, | ||
"plugins": [ | ||
"@typescript-eslint", | ||
"deprecation", | ||
"functional", | ||
"import", | ||
"jest", | ||
"prettier" | ||
], | ||
"extends": [ | ||
"eslint:recommended", | ||
"plugin:@typescript-eslint/recommended", | ||
"plugin:@typescript-eslint/recommended-requiring-type-checking", | ||
"prettier", | ||
"plugin:prettier/recommended", | ||
"plugin:import/recommended", | ||
"plugin:import/typescript", | ||
"plugin:functional/external-recommended", | ||
"plugin:functional/no-mutations", | ||
"plugin:jest/recommended" | ||
], | ||
"parser": "@typescript-eslint/parser", | ||
"parserOptions": { | ||
"project": "./tsconfig.json" | ||
}, | ||
"env": { | ||
"jest/globals": true | ||
}, | ||
"rules": { | ||
"no-console": ["warn", { "allow": ["error", "info", "table", "warn"] }], | ||
"no-undef": "error", | ||
"sort-imports": ["error", { "ignoreDeclarationSort": true }], | ||
"@typescript-eslint/consistent-type-imports": "error", | ||
"@typescript-eslint/explicit-module-boundary-types": "off", | ||
"@typescript-eslint/member-ordering": "error", | ||
"@typescript-eslint/no-empty-function": "off", | ||
"@typescript-eslint/no-explicit-any": "off", | ||
"@typescript-eslint/no-floating-promises": "error", | ||
"@typescript-eslint/no-unnecessary-condition": "error", | ||
"@typescript-eslint/no-unnecessary-type-assertion": "error", | ||
"@typescript-eslint/no-shadow": "error", | ||
"@typescript-eslint/prefer-readonly-parameter-types": "off", | ||
// "deprecation/deprecation": "warn", | ||
"functional/immutable-data": ["error", { "ignorePattern": "this" }], | ||
"functional/no-let": "off", | ||
"functional/prefer-readonly-type": [ | ||
"error", | ||
{ "ignoreClass": "fieldsOnly" } | ||
], | ||
"import/extensions": ["error", "always", { "ts": "never", "tsx": "never" }], | ||
"import/first": "error", | ||
"import/newline-after-import": "error", | ||
"import/no-absolute-path": "error", | ||
"import/no-amd": "error", | ||
"import/no-commonjs": "error", | ||
"import/no-cycle": "error", | ||
"import/no-deprecated": "error", | ||
"import/no-dynamic-require": "error", | ||
"import/no-mutable-exports": "error", | ||
"import/no-self-import": "error", | ||
"import/no-unused-modules": "error", | ||
"import/no-useless-path-segments": "error", | ||
"import/order": [ | ||
"error", | ||
{ "alphabetize": { "order": "asc" }, "newlines-between": "always" } | ||
], | ||
"import/unambiguous": "error" | ||
}, | ||
"overrides": [ | ||
{ | ||
"files": ["**/*.test.ts"], | ||
"rules": { | ||
"@typescript-eslint/no-unsafe-argument": "off", | ||
"@typescript-eslint/no-unsafe-call": "off", | ||
"@typescript-eslint/no-unsafe-member-access": "off", | ||
"@typescript-eslint/no-unsafe-return": "off" | ||
} | ||
} | ||
] | ||
"extends": ["@swim-io"] | ||
} |
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.
if we go for typescript only projects can't we include these as dependencies (and the typescript specific ones). Wouldn't that be more convenient?
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.
Unfortunately not (I went down several tunnels in this rabbit hole). First of all plugins and configs are treated very differently and get resolved differently. ESLint says this:
However, we can't actually do that with the prettier config because it's an optional dependency of
eslint-plugin-prettier
: prettier/eslint-plugin-prettier#451. Which means we have to include it as a dependency of whatever loads the plugin if I understand correctly (also didn't get it to work any other way).I also couldn't get the TS parser to work as a dependency, and I didn't work out why.
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.
I think they're working on changing all of this but this issue has been open since 2015: eslint/eslint#3458
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.
I have an example of a similar package we used in my previous job, see https://github.com/denis-sokolov/eslint-plugin/blob/master/package.json but I didn't set it up myself so I'm missing the little details
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.
But I see airbnb also lists that peer dependencies step https://github.com/airbnb/javascript/tree/master/packages/eslint-config-airbnb#eslint-config-airbnb-1
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.
This was somewhat helpful: https://zaicevas.com/blog/how-eslint-resolves-plugins-and-shareable-configs
It might well be that it's yarn that won't let us break the rules.
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.
What if we'll add
postinstall
script that will automatically install peer dependencies?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.
As of Yarn v2, Yarn won't run this automatically: https://yarnpkg.com/getting-started/migration#explicitly-call-the-pre-and-post-scripts
But that could be a good thing! I think it's also OK as it is, since we only need to add them once per package.
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.
Oh actually maybe it does do that for dependencies otherwise everything would probably break.
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.
Not sure this is even possible on reflection. The
postinstall
script will run in the scope of the dependency, but we actually need to add them to the consuming package.