Skip to content

Commit

Permalink
Initial version
Browse files Browse the repository at this point in the history
  • Loading branch information
Javier Maestre committed Oct 24, 2020
1 parent 9bde385 commit c6f8e4d
Show file tree
Hide file tree
Showing 17 changed files with 441 additions and 0 deletions.
Binary file added .DS_Store
Binary file not shown.
10 changes: 10 additions & 0 deletions .editorconfig
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
# EditorConfig is awesome: http://editorconfig.org/
root = true

[*]
charset = utf-8
end_of_line = lf
indent_size = 2
indent_style = space
insert_final_newline = true
trim_trailing_whitespace = true
2 changes: 2 additions & 0 deletions .eslintignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
node_modules/
package-lock.json
4 changes: 4 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
/node_modules

yarn-error.log
yarn.lock
10 changes: 10 additions & 0 deletions .prettierrc.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
module.exports = {
printWidth: 120,
tabWidth: 2,
singleQuote: true,
trailingComma: 'none',
semi: true,
'newline-before-return': true,
'no-duplicate-variable': [true, 'check-parameters'],
'no-var-keyword': true
};
15 changes: 15 additions & 0 deletions _prettier-react-typescript.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
module.exports = {
root: true,
parserOptions: {
sourceType: 'module',
ecmaFeatures: {
jsx: true,
modules: true
}
},
env: {
browser: true,
es6: true
},
extends: ['airbnb', 'prettier', 'prettier/react', 'prettier/@typescript-eslint']
};
15 changes: 15 additions & 0 deletions _prettier-react.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
module.exports = {
root: true,
parserOptions: {
sourceType: 'module',
ecmaFeatures: {
jsx: true,
modules: true
}
},
env: {
browser: true,
es6: true
},
extends: ['airbnb', 'prettier', 'prettier/react']
};
15 changes: 15 additions & 0 deletions _prettier.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
module.exports = {
root: true,
parserOptions: {
sourceType: 'module',
ecmaFeatures: {
jsx: true,
modules: true
}
},
env: {
browser: true,
es6: true
},
extends: ['airbnb', 'prettier']
};
18 changes: 18 additions & 0 deletions a11y.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
module.exports = {
root: true,
parserOptions: {
sourceType: 'module',
ecmaFeatures: {
jsx: true,
modules: true
}
},
env: {
browser: true,
es6: true
},
extends: [],
plugins: ['jsx-a11y'],
globals: {},
rules: {}
};
11 changes: 11 additions & 0 deletions core.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
// All the avaible rules in detail: https://eslint.org/docs/rules/
module.exports = {
extends: ['airbnb'],
rules: {
'comma-dangle': ['error', 'only-multiline'], // Require trailing-comma only on multilines: https://eslint.org/docs/rules/comma-dangle#options-14
'object-curly-newline': 'off', // Can be managed with prettier rules
'max-len': ['error', { code: 120, tabWidth: 2, ignoreComments: true }], // It's aligned with the config of .prettierrc.js
'implicit-arrow-linebreak': 'off', // Prettier will manage this rule
'function-paren-newline': 'off' // Prettier will manage this rule
}
};
143 changes: 143 additions & 0 deletions docs/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,143 @@
# ESLint configs

This project have presets for ESLint which I use in private projects:

## Available configs

- `@javiermaestre/eslint-config/a11y` - Accessibility rules from [eslint-plugin-jsx-a11y](https://github.com/jsx-eslint/eslint-plugin-jsx-a11y#readme)
- `@javiermaestre/eslint-config/core` - ESLINT base config from [eslint-config-airbnb](https://github.com/airbnb/javascript)
- `@javiermaestre/eslint-config/react` - Based on React rules of `Airbnb`
- `@javiermaestre/eslint-config/react-hooks` - Based on React Hooks rules of `Airbnb`
- `@javiermaestre/eslint-config/react-typescript` - Based on [@typescript-eslint/eslint-plugin](https://github.com/typescript-eslint/typescript-eslint#readme)

## Install

Install as a DEV dependency

```bash
yarn add --dev @javiermaestre/eslint-config
npm install --D @javiermaestre/eslint-config
```

## Extend

Extend configs creating a `.eslintrc.js` or `eslintrc.json` file on your project:

```js
// eslintrc.js
module.exports = {
extends: [
'@javiermaestre/eslint-config/core',
'@javiermaestre/eslint-config/react',
'@javiermaestre/eslint-config/react-hooks',
'@javiermaestre/eslint-config/react-typescript'
]
};
```

```json
// eslintrc.json
{
"extends": ["@javiermaestre/eslint-config/core", "@javiermaestre/eslint-config/react-typescript"]
}
```

Also, you can override and customise rules:

- Set the config properties of ESLINT, like [`env`](http://eslint.org/docs/user-guide/configuring#specifying-environments) [`parserOptions`](http://eslint.org/docs/user-guide/configuring#specifying-parser-options),
or others as you like ([`ESLINT documentation`](http://eslint.org/docs/user-guide/configuring))
- Override specific rules for your project

## Default configs

This are configs ready to use:

- Config for JS

```js
// eslintrc.js
module.exports = {
extends: ['@javiermaestre/eslint-config/core']
};
```

- Config for Typescript

```js
// eslintrc.js
module.exports = {
extends: ['@javiermaestre/eslint-config/typescript']
};
```

- Config for React

```js
// eslintrc.js
module.exports = {
extends: [
'@javiermaestre/eslint-config/react' // React package extends from /core
]
};
```

- Config for React with Typescript

```js
// eslintrc.js
module.exports = {
extends: [
'@javiermaestre/eslint-config/react-typescript' // React Typescript package extends from /react and /core
]
};
```

- Config for React with Typescript and Hooks

```js
// eslintrc.js
module.exports = {
extends: [
'@javiermaestre/eslint-config/react-typescript', // React Typescript package with Hooks extends from /react and /core
'@javiermaestre/eslint-config/react-hooks'
]
};
```

## Extra configuration

The plugin is ready to work with:

- Prettier - Adding a `.prettierrc` file
- Editorconfig - Adding a `.editorconfig` file

You can override the settings on this files

## Run linter

- For report

```bash
eslint --ext .js,.jsx .
```

- For auto fixing

```bash
eslint --ext .js,.jsx . --fix
```

## Next steps

Add support for:

```js

// for Node.js projects
'@javiermaestre/eslint-config/node',

// for Angular projects
'@javiermaestre/eslint-config/angular',

...
```
9 changes: 9 additions & 0 deletions eslintrc.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
module.exports = {
extends: ['./config/core.js'],
parserOptions: {
sourceType: 'module',
ecmaVersion: 2020
},
reportUnusedDisableDirectives: true,
root: true
};
34 changes: 34 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
{
"name": "@javiermaestre/eslint-config",
"version": "1.0.0",
"description": "ESLint config for projects (ESLint + Airbnb + TypeScript + Prettier)",
"publishConfig": {
"registry": "https://npm.pkg.github.com/"
},
"license": "MIT",
"scripts": {},
"engines": {
"node": ">=10"
},
"peerDependencies": {
"eslint": "7.x",
"prettier": "2.x",
"typescript": "3.x"
},
"dependencies": {
"@typescript-eslint/eslint-plugin": "3.8.0",
"@typescript-eslint/parser": "3.8.0",
"eslint-config-airbnb": "18.2.0",
"eslint-config-prettier": "6.11.0",
"eslint-plugin-import": "2.22.0",
"eslint-plugin-jsx-a11y": "6.3.1",
"eslint-plugin-prettier": "3.1.4",
"eslint-plugin-react": "7.20.6",
"eslint-plugin-react-hooks": "4.1.0"
},
"devDependencies": {
"eslint": "7.x",
"prettier": "2.x",
"typescript": "3.x"
}
}
3 changes: 3 additions & 0 deletions react-hooks.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
module.exports = {
extends: ['airbnb/hooks']
};
56 changes: 56 additions & 0 deletions react-typescript.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
module.exports = {
parser: '@typescript-eslint/parser',
parserOptions: {
project: './tsconfig.json',
sourceType: 'module',
ecmaFeatures: {
jsx: true,
modules: true
}
},
env: {
browser: true,
es6: true
},
extends: [
'./core.js',
'plugin:@typescript-eslint/recommended',
'plugin:import/typescript',
'./_prettier-react-typescript.js',
'./react.js'
],
plugins: ['import', '@typescript-eslint'],
rules: {
// Import
'import/prefer-default-export': 'off',
'import/extensions': [
'error',
'ignorePackages',
{
js: 'never',
mjs: 'never',
jsx: 'never',
ts: 'never',
tsx: 'never'
}
],
// TypeScript
'@typescript-eslint/no-unused-vars': 'error',
'@typescript-eslint/explicit-member-accessibility': 'off',
'@typescript-eslint/no-object-literal-type-assertion': 'off',
'@typescript-eslint/prefer-interface': 'off',
'@typescript-eslint/camelcase': 'off',
'@typescript-eslint/explicit-function-return-type': 'off',
'@typescript-eslint/no-explicit-any': 'off',
// Other
radix: 'warn'
},
settings: {
'import/resolver': {
node: {
extensions: ['.js', '.jsx', '.ts', '.tsx'],
moduleDirectory: ['node_modules', 'src']
}
}
}
};
Loading

0 comments on commit c6f8e4d

Please sign in to comment.