Skip to content

Commit

Permalink
Merge pull request #4 from rambler-digital-solutions/prettier
Browse files Browse the repository at this point in the history
feat(eslint-config): include prettier in config
  • Loading branch information
andrepolischuk authored Feb 21, 2024
2 parents 03b6b6a + ecbfe17 commit 6a4ff33
Show file tree
Hide file tree
Showing 10 changed files with 48 additions and 43 deletions.
5 changes: 1 addition & 4 deletions .eslintrc.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,3 @@
{
"extends": ["@rambler-tech/eslint-config", "prettier"],
"parserOptions": {
"requireConfigFile": false
}
"extends": ["@rambler-tech/eslint-config"]
}
1 change: 0 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@
"devDependencies": {
"@commitlint/cli": "^17",
"eslint": "^8.49.0",
"eslint-config-prettier": "^9.0.0",
"husky": "^8.0.3",
"lerna": "^7.3.0",
"lint-staged": "^14.0.1",
Expand Down
63 changes: 34 additions & 29 deletions packages/eslint-config/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,70 +3,76 @@
## Install

```
npm install -D eslint @rambler-tech/eslint-config eslint-config-prettier
npm install -D eslint @rambler-tech/eslint-config
```

or

```
yarn add -D eslint @rambler-tech/eslint-config eslint-config-prettier
yarn add -D eslint @rambler-tech/eslint-config
```

## Usage

Create a `.eslinrc.json` and extend this config. Make sure to put [`eslint-config-prettier`](https://github.com/prettier/eslint-config-prettier) last, so it gets the chance to override other configs
Included base configs:

- `@rambler-tech/eslint-config` - base JavaScript
- `@rambler-tech/eslint-config/semi` - base with semicolons and trailing commas

Included special configs:

- `@rambler-tech/eslint-config/ts` - TypeScript
- `@rambler-tech/eslint-config/react` - React
- `@rambler-tech/eslint-config/next` - Next.js

Example `.eslintrc.json` for React project:

```json
{
"extends": [
"@rambler-tech/eslint-config",
"@rambler-tech/eslint-config/ts",
"prettier"
"@rambler-tech/eslint-config/react"
]
}
```

or add a key to your **package.json** file.
Example `.eslintrc.json` for TypeScript project:

```json
"eslintConfig": {
{
"extends": [
"@rambler-tech/eslint-config",
"@rambler-tech/eslint-config/ts",
"prettier"
"@rambler-tech/eslint-config/ts"
]
}
```

## Included configurations

Use proper configs at the same time depending on your stack.

Included base configs:

- `@rambler-tech/eslint-config` - base JavaScript
- `@rambler-tech/eslint-config/semi` - base with semicolons and trailing commas

Included special configs:
Example `.eslintrc.json` for TypeScript React project:

- `@rambler-tech/eslint-config/ts` - TypeScript
- `@rambler-tech/eslint-config/react` - React
- `@rambler-tech/eslint-config/next` - Next.js
```json
{
"extends": [
"@rambler-tech/eslint-config",
"@rambler-tech/eslint-config/react",
"@rambler-tech/eslint-config/ts"
]
}
```

Note that the `@rambler-tech/eslint-config/ts` should be second to last in the list (before the 'prettier') since it includes `@typescript-eslint/parser`:
Example `.eslintrc.json` for TypeScript Next.js project:

```json
"eslintConfig": {
{
"extends": [
"@rambler-tech/eslint-config",
"@rambler-tech/eslint-config/react",
"@rambler-tech/eslint-config/next",
"@rambler-tech/eslint-config/ts",
"prettier"
"@rambler-tech/eslint-config/ts"
]
}
```

Note that the `@rambler-tech/eslint-config/ts` should be second to last in the list since it includes `@typescript-eslint/parser`:

## Module resolution

Included [`eslint-plugin-import`](https://github.com/import-js/eslint-plugin-import) requires additional settings if you use custom module resolution. For example if you use aliases instead of long relative paths:
Expand All @@ -83,8 +89,7 @@ To use resolution options from `tsconfig.json` add the following settings to you
{
"extends": [
"@rambler-tech/eslint-config",
"@rambler-tech/eslint-config/ts",
"prettier"
"@rambler-tech/eslint-config/ts"
],
"settings": {
"import/resolver": {
Expand Down
3 changes: 2 additions & 1 deletion packages/eslint-config/js.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,8 @@ module.exports = {
'plugin:import/recommended',
'plugin:sonar/recommended',
'plugin:sonarjs/recommended',
'plugin:security/recommended-legacy'
'plugin:security/recommended-legacy',
'prettier'
],
plugins: ['promise', 'unicorn', 'todo-with-label'],
rules: {
Expand Down
2 changes: 1 addition & 1 deletion packages/eslint-config/next.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
require('@rushstack/eslint-patch/modern-module-resolution')

module.exports = {
extends: ['next'],
extends: ['./react.js', 'next', 'prettier'],
rules: {
'@next/next/no-img-element': 0
}
Expand Down
1 change: 1 addition & 0 deletions packages/eslint-config/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
"@typescript-eslint/eslint-plugin": "^6.21.0",
"@typescript-eslint/parser": "^6.21.0",
"eslint-config-next": "^14.1.0",
"eslint-config-prettier": "^9.1.0",
"eslint-import-resolver-typescript": "^3.6.1",
"eslint-import-resolver-webpack": "^0.13.8",
"eslint-plugin-import": "^2.29.1",
Expand Down
3 changes: 2 additions & 1 deletion packages/eslint-config/react.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,8 @@ module.exports = {
'plugin:jsx-a11y/recommended',
'plugin:ssr-friendly/recommended',
'plugin:react-prefer-function-component/recommended',
'plugin:storybook/recommended'
'plugin:storybook/recommended',
'prettier'
],
rules: {
'react/prop-types': 'off',
Expand Down
2 changes: 1 addition & 1 deletion packages/eslint-config/semi.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
module.exports = {
extends: '@rambler-tech/eslint-config',
extends: ['./js.js'],
rules: {
semi: ['error', 'always'],
'comma-dangle': ['error', 'only-multiline']
Expand Down
3 changes: 2 additions & 1 deletion packages/eslint-config/ts.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,8 @@ module.exports = {
files: ['*.ts', '*.mts', '*.cts', '*.tsx'],
extends: [
'plugin:@typescript-eslint/recommended',
'plugin:import/typescript'
'plugin:import/typescript',
'prettier'
],
rules: {
'no-unused-vars': 'off',
Expand Down
8 changes: 4 additions & 4 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -2611,10 +2611,10 @@ eslint-config-next@^14.1.0:
eslint-plugin-react "^7.33.2"
eslint-plugin-react-hooks "^4.5.0 || 5.0.0-canary-7118f5dd7-20230705"

eslint-config-prettier@^9.0.0:
version "9.0.0"
resolved "https://registry.yarnpkg.com/eslint-config-prettier/-/eslint-config-prettier-9.0.0.tgz#eb25485946dd0c66cd216a46232dc05451518d1f"
integrity sha512-IcJsTkJae2S35pRsRAwoCE+925rJJStOdkKnLVgtE+tEpqU0EVVM7OqrwxqgptKdX29NUwC82I5pXsGFIgSevw==
eslint-config-prettier@^9.1.0:
version "9.1.0"
resolved "https://registry.yarnpkg.com/eslint-config-prettier/-/eslint-config-prettier-9.1.0.tgz#31af3d94578645966c082fcb71a5846d3c94867f"
integrity sha512-NSWl5BFQWEPi1j4TjVNItzYV7dZXZ+wP6I6ZhrBGpChQhZRUaElihE9uRRkcbRnNb76UMKDF3r+WTmNcGPKsqw==

eslint-import-resolver-node@^0.3.6, eslint-import-resolver-node@^0.3.7, eslint-import-resolver-node@^0.3.9:
version "0.3.9"
Expand Down

0 comments on commit 6a4ff33

Please sign in to comment.