-
-
Notifications
You must be signed in to change notification settings - Fork 59
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Copy maily from the @wpquark/eslint-config upstream and create one for typescript as well. See #434
- Loading branch information
Showing
23 changed files
with
472 additions
and
40 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,34 @@ | ||
module.exports = { | ||
extends: [ | ||
'@wpquark', | ||
'plugin:@typescript-eslint/recommended', | ||
'plugin:@typescript-eslint/recommended', | ||
'prettier', | ||
'prettier/@typescript-eslint', | ||
], | ||
parser: '@typescript-eslint/parser', | ||
parserOptions: { | ||
project: './tsconfig.json', | ||
tsconfigRootDir: __dirname, | ||
}, | ||
rules: { | ||
'import/prefer-default-export': 'off', | ||
'@typescript-eslint/explicit-function-return-type': 'off', | ||
'@typescript-eslint/explicit-member-accessibility': 'off', | ||
'class-methods-use-this': 'off', | ||
'@typescript-eslint/no-explicit-any': 'off', | ||
'import/no-cycle': 'off', | ||
'import/no-dynamic-require': 'off', | ||
'import/named': 'off', | ||
}, | ||
settings: { | ||
'import/parsers': { | ||
'@typescript-eslint/parser': ['.ts', '.tsx'], | ||
}, | ||
'import/resolver': { | ||
typescript: { | ||
directory: __dirname, | ||
}, | ||
}, | ||
}, | ||
}; |
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 |
---|---|---|
@@ -0,0 +1 @@ | ||
module.exports = require('./index'); |
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,34 @@ | ||
# Logs | ||
logs | ||
*.log | ||
|
||
# Runtime data | ||
pids | ||
*.pid | ||
*.seed | ||
|
||
# Directory for instrumented libs generated by jscoverage/JSCover | ||
lib-cov | ||
|
||
# Coverage directory used by tools like istanbul | ||
coverage | ||
|
||
# Grunt intermediate storage (http://gruntjs.com/creating-plugins#storing-task-files) | ||
.grunt | ||
|
||
# node-waf configuration | ||
.lock-wscript | ||
|
||
# Compiled binary addons (http://nodejs.org/api/addons.html) | ||
build/Release | ||
|
||
# Dependency directory | ||
# https://www.npmjs.org/doc/misc/npm-faq.html#should-i-check-my-node_modules-folder-into-git | ||
node_modules | ||
*.un~ | ||
yarn.lock | ||
src | ||
flow-typed | ||
coverage | ||
decls | ||
examples |
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,111 @@ | ||
# `@wpackio/eslint-config` | ||
|
||
Shared ESLint configuration for all `@wpackio` packages and more. It has shared | ||
config for both JavaScript and TypeScript projects. | ||
|
||
Note that this doesn't come installed with `@wpackio/scripts`. If you wish to | ||
take advantage of this config, then install and use on your own. | ||
|
||
## Installation | ||
|
||
If using `yarn` | ||
|
||
```bash | ||
yarn add --dev @wpackio/eslint-config eslint prettier | ||
``` | ||
|
||
or with `npm` | ||
|
||
```bash | ||
npm i -D @wpackio/eslint-config eslint prettier | ||
``` | ||
|
||
## Usage with JavaScript | ||
|
||
Using it with JavaScript project is very simple. Create a `.eslintrc.js` file in the root of your project and put the code. | ||
|
||
```js | ||
module.exports = { | ||
extends: '@wpackio', | ||
}; | ||
``` | ||
|
||
## Usage with TypeScript | ||
|
||
Using with typescript requires a little more effort. In the same `.eslintrc.js` | ||
file, put | ||
|
||
```js | ||
module.exports = { | ||
extends: ['@wpackio/eslint-config/ts'], | ||
parserOptions: { | ||
project: './tsconfig.json', | ||
tsconfigRootDir: __dirname, | ||
}, | ||
settings: { | ||
'import/resolver': { | ||
typescript: { | ||
directory: __dirname, | ||
}, | ||
}, | ||
}, | ||
}; | ||
``` | ||
|
||
Putting `__dirname` in `parserOptions.tsconfigRootDir` and `['import/resolver'].typescript` | ||
is necessary because of [this issue](https://github.com/typescript-eslint/typescript-eslint/issues/251). | ||
|
||
For both the cases you can also extend upon the rules. | ||
|
||
## Prettier config | ||
|
||
Create a `prettier.config.js` file in the root of your project and put the code. | ||
|
||
```js | ||
module.exports = require('@wpackio/eslint-config/prettier.config'); | ||
``` | ||
|
||
Now you are ready to go. | ||
|
||
## VSCode Integration | ||
|
||
Install the [eslint](https://marketplace.visualstudio.com/items?itemName=dbaeumer.vscode-eslint) | ||
plugin for VSCode. Enable autoFormat for `javascript` and `javascriptreact` files. | ||
|
||
- Go to Code > Preference [File > Preference for Windows & Linux]. | ||
- Edit the WorkSpace Settings (Recommended). | ||
|
||
```json | ||
{ | ||
"eslint.autoFixOnSave": true, | ||
"[javascript]": { | ||
"editor.formatOnSave": false | ||
}, | ||
"[javascriptreact]": { | ||
"editor.formatOnSave": false | ||
} | ||
} | ||
``` | ||
|
||
If you are using for typescript files, the following additional settings are needed. | ||
|
||
```json | ||
{ | ||
"eslint.validate": [ | ||
"javascript", | ||
"javascriptreact", | ||
{ "language": "typescript", "autoFix": true }, | ||
{ "language": "typescriptreact", "autoFix": true } | ||
] | ||
} | ||
``` | ||
|
||
## Development | ||
|
||
This package has the same `npm scripts` as this monorepo. These should be run | ||
using `lerna run <script>`. More information can be found under [CONTRIBUTION.md](../../CONTRIBUTION.md). | ||
|
||
- `build`: Use babel to build for nodejs 8.6+. Files inside `src` are compiled and put under `lib`. All type definitions are stripped and individual type declaration files are created. | ||
- `prepare`: Run `build` after `yarn` and before `publish`. | ||
- `lint`: Lint all files using tslint. | ||
- `test`: Run tests on files using jest. |
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 @@ | ||
module.exports = require('../../babel.config.js'); |
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,8 @@ | ||
// Default set of env rules for ESLint | ||
|
||
module.exports = { | ||
browser: true, | ||
commonjs: true, | ||
es6: true, | ||
node: true, | ||
}; |
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,10 @@ | ||
// Default extends (from where we inherit our config) | ||
|
||
module.exports = [ | ||
'airbnb', | ||
'plugin:jest/recommended', | ||
'plugin:prettier/recommended', | ||
'prettier', | ||
'prettier/react', | ||
'prettier/babel', | ||
]; |
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,69 @@ | ||
// Default sets of rules for ESLint | ||
|
||
module.exports = { | ||
// =================================== | ||
// Some rules from eslint-plugin-babel | ||
// =================================== | ||
// First turn them off | ||
'new-cap': 'off', | ||
camelcase: 'off', | ||
'no-invalid-this': 'off', | ||
'object-curly-spacing': 'off', | ||
semi: 'off', | ||
'no-unused-expressions': 'off', | ||
'valid-typeof': 'off', | ||
// require a capital letter for constructors | ||
'babel/new-cap': [ | ||
'error', | ||
{ | ||
newIsCap: true, | ||
newIsCapExceptions: [], | ||
capIsNew: false, | ||
capIsNewExceptions: [ | ||
'Immutable.Map', | ||
'Immutable.Set', | ||
'Immutable.List', | ||
], | ||
}, | ||
], | ||
// require camel case names | ||
// This one is enhanced from airbnb and accounts for destructuring | ||
// and react UNSAFE_component* methods. | ||
'babel/camelcase': [ | ||
'error', | ||
{ | ||
properties: 'never', | ||
ignoreDestructuring: true, | ||
}, | ||
], | ||
// We would force invalid this rules | ||
// But would only warn about it | ||
'babel/no-invalid-this': 'warn', | ||
// We don't configure curly spacing because of prettier | ||
'babel/object-curly-spacing': 'off', | ||
// We don't configure babel/semi because of prettier | ||
'babel/semi': 'off', | ||
// disallow usage of expressions in statement position | ||
'babel/no-unused-expressions': [ | ||
'error', | ||
{ | ||
allowShortCircuit: false, | ||
allowTernary: false, | ||
allowTaggedTemplates: false, | ||
}, | ||
], | ||
// ensure that the results of typeof are compared against a valid string | ||
// https://eslint.org/docs/rules/valid-typeof | ||
'babel/valid-typeof': ['error', { requireStringLiterals: true }], | ||
'react/no-unused-prop-types': 1, | ||
'react/no-unused-state': 1, | ||
'no-unused-vars': 1, | ||
'prettier/prettier': ['error'], | ||
'no-console': 0, | ||
'no-plusplus': [ | ||
2, | ||
{ | ||
allowForLoopAfterthoughts: true, | ||
}, | ||
], | ||
}; |
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,27 @@ | ||
// Copyright (c) 2018 Swashata Ghosh <[email protected]> | ||
// | ||
// This software is released under the MIT License. | ||
// https://opensource.org/licenses/MIT | ||
|
||
// Use this configuration for standard JavaScript Projects. | ||
|
||
const rules = require('./config/rules'); | ||
const env = require('./config/env'); | ||
const ex = require('./config/extends'); | ||
|
||
module.exports = { | ||
env, | ||
extends: ex, | ||
parser: 'babel-eslint', | ||
parserOptions: { | ||
ecmaVersion: 2018, | ||
ecmaFeatures: { | ||
jsx: true, | ||
}, | ||
sourceType: 'module', | ||
}, | ||
plugins: ['babel'], | ||
rules: { | ||
...rules, | ||
}, | ||
}; |
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,46 @@ | ||
{ | ||
"name": "@wpackio/eslint-config", | ||
"version": "0.0.1", | ||
"description": "Shared ESLint config for all @wpackio packages.", | ||
"keywords": [ | ||
"eslint", | ||
"typescript", | ||
"eslint-config", | ||
"eslint-typescript-config" | ||
], | ||
"main": "index.js", | ||
"repository": "https://github.com/swashata/wp-webpack-script", | ||
"homepage": "https://wpack.io", | ||
"author": "Swashata Ghosh <[email protected]> (https://swas.io)", | ||
"license": "MIT", | ||
"private": false, | ||
"peerDependencies": { | ||
"eslint": ">=5.3.0", | ||
"prettier": ">=1.12.1" | ||
}, | ||
"dependencies": { | ||
"babel-eslint": "^10.0.1", | ||
"eslint-config-airbnb": "^17.1.0", | ||
"eslint-config-prettier": "^4.1.0", | ||
"eslint-plugin-babel": "^5.3.0", | ||
"eslint-plugin-import": "^2.17.1", | ||
"eslint-plugin-jest": "^22.4.1", | ||
"eslint-plugin-jsx-a11y": "^6.2.1", | ||
"eslint-plugin-prettier": "^3.0.1", | ||
"eslint-plugin-react": "^7.12.4", | ||
"@typescript-eslint/eslint-plugin": "1.6.0", | ||
"@typescript-eslint/parser": "1.6.0", | ||
"eslint-import-resolver-typescript": "1.1.1" | ||
}, | ||
"engines": { | ||
"node": ">=8.9.0" | ||
}, | ||
"scripts": {}, | ||
"publishConfig": { | ||
"access": "public" | ||
}, | ||
"devDependencies": { | ||
"eslint": "^5.16.0", | ||
"prettier": "^1.17.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 |
---|---|---|
@@ -0,0 +1,15 @@ | ||
// Copyright (c) 2018 Swashata Ghosh <[email protected]> | ||
// | ||
// This software is released under the MIT License. | ||
// https://opensource.org/licenses/MIT | ||
|
||
module.exports = { | ||
useTabs: true, | ||
tabWidth: 4, | ||
semi: true, | ||
singleQuote: true, | ||
trailingComma: 'es5', | ||
bracketSpacing: true, | ||
jsxBracketSameLine: false, | ||
arrowParens: 'avoid', | ||
}; |
Oops, something went wrong.