0.0.1 • Published 3 years ago

@happ/eslint-plugin v0.0.1

Weekly downloads
-
License
MIT
Repository
github
Last release
3 years ago

@happ/eslint-plugin

Best all in eslint config.

Config for javascript, typescript, angular, jest, cypress, json, markdown

Included best plugins. Such as unicorn, sonarjs, import, promise

Prettier and Nx support

Higly recommended to use in pair with @happ/prettier-config

Content

  1. Install
  2. Configs
  3. Prettier
  4. Nx
  5. Autolint

Install

  1. Install pnpm i -D @happ/eslint-plugin

Configs

  1. Javascript
  2. Typescript
  3. Angular
  4. Angular template
  5. Cypress
  6. Jest
  7. Json
  8. Markdown

Javascript

  1. Update .eslintrc.json:
{
	...
	overrides: [
		{
			extends: ["plugin:@happ/javascript"],
		},
	],
	...
}

By default javascript rules used for .js and .jsx files. If you want to change it, just set "filex": ["..."]

Typescript

Important. Use it only in pair with javascript config

  1. Update tsconfig.*.json:
{
	compilerOptions: {
		strictNullChecks: true,
	}
}
  1. Update .eslintrc.json:
{
	...
	overrides: [
		{
			extends: ["plugin:@happ/typescript"],
		},
	],
	...
}

By default javascript rules used for .ts and .tsx files. If you want to change it, just set "filex": ["..."]

Angular

  1. Update .eslintrc.json:
{
	...
	overrides: [
		{
			extends: ["plugin:@happ/angular"],
		},
	],
	...
}

By default javascript rules used for .component.ts and .service.ts files. If you want to change it, just set "filex": ["..."]

Angular template

Important. Use it only in pair with angular config

  1. Update .eslintrc.json:
{
	...
	overrides: [
		{
			extends: ["plugin:@happ/angular-template"],
		},
	],
	...
}

By default javascript rules used for .component.html files. If you want to change it, just set "filex": ["..."]

Cypress

  1. Update .eslintrc.json:
{
	...
	overrides: [
		{
			extends: ["plugin:@happ/cypress"],
		},
	],
	...
}

By default javascript rules used for .spec.ts and .spec.js files. If you want to change it, just set "filex": ["..."]

Jest

  1. Update .eslintrc.json:
{
	...
	overrides: [
		{
			extends: ["plugin:@happ/jest"],
		},
	],
	...
}

By default javascript rules used for .spec.ts and .spec.js files. If you want to change it, just set "filex": ["..."]

Json

  1. Update .eslintrc.json:
{
	...
	overrides: [
		{
			extends: ["plugin:@happ/json"],
		},
	],
	...
}

By default javascript rules used for .json files. If you want to change it, just set "filex": ["..."]

Markdown

  1. Update .eslintrc.json:
{
	...
	overrides: [
		{
			extends: ["plugin:@happ/markdown"],
		},
	],
	...
}

By default javascript rules used for .md files. If you want to change it, just set "filex": ["..."]

Prettier:

Prettier

  1. Install pnpm i -D @happ/prettier-config
  2. Update prettier.config.js:
module.exports = {
	...require("@happ/prettier-config"),
};
  1. Update .eslint.json
{
	...
	overrides: [
		{
			extends: ["plugin:@happ/prettier"],
		},
	],
	...
}

Nx

If you are using nx and wanna to use nx lint you have to setup executor

  1. Update workspace.json:
{
	...
	"lint": {
		"executor": "@nrwl/linter:eslint",
		"options": {
			 "lintFilePatterns": [
				 "libs/LIB_NAME/**/*.js",
				 "libs/LIB_NAME/**/*.ts",
				 "libs/LIB_NAME/**/*.md",
				 "libs/LIB_NAME/**/*.json"
			],
			"ignorePath": "libs/LIB_NAME/.eslintignore"
		}
	}
	...
}
  1. Create libs/LIB_NAME/.eslintignore with files, which don't need to lint

Autolint

  1. Webstorm
  2. Visual studio code

Webstorm

Webstorm

Base

  1. Open preferences:
    1. MacOS: ⌘ + ,
    2. Windows Ctrl + Alt + S
  2. Move to Languages & Frameworks -> JavaScript -> Code Quality Tools -> Eslint
  3. Set true for Run eslint --fix on save checkbox

For json

  1. Open preferences:
    1. MacOS: ⌘ + ,
    2. Windows Ctrl + Alt + S
  2. Move to Tools -> File Watchers
  3. Click on + to create a new one
  4. Fill the fields:
    1. Name: JSON
    2. File Type: JSON
    3. Program: /YOUR_DIR/node_modules/.bin/eslint
    4. Arguments: $FilePath$ --fix
    5. Output path to regresh: $FilePath$ --fix
    6. Working directory: YOUR_DIR
  5. Click on Save to save the changes

If you have tsconfig.*.json you have to move it to JSON file type:

  1. Preferences -> Editor -> File Types
  2. Find JSON type and add tsconfig.app.json and e.t.c. to the list

Visual stuido code

Visual studio code

  1. Open preferences:
    1. MacOS: ⌘ + ,
    2. Windows Ctrl + Alt + S
  2. Move to JSON format
  3. Update preferences
{
	...
	"editor.codeActionsOnSave": {
		"source.fixAll.eslint": true,
	},
	...
}

If you have files which generated automatically (jest.config.js or jest.preset.js) better to add them to .eslintignore

Used plugins:

  1. Javascript plugins
  2. Typescript plugins
  3. Angular plugins
  4. Jest plugins
  5. Cypress plugins
  6. Json plugins
  7. Markdown plugins

Javascript plugins

  1. eslint-plugin-unicorn
  2. eslint-plugin-sonarjs
  3. eslint-plugin-compat
  4. eslint-plugin-es
  5. eslint-plugin-deprecate
  6. eslint-plugin-deprecation
  7. eslint-plugin-markdown
  8. eslint-plugin-import
  9. @html-eslint/eslint-plugin
  10. eslint-plugin-eslint-comments
  11. eslint-plugin-promise
  12. eslint-plugin-array-func
  13. eslint-plugin-prefer-arrow
  14. eslint-plugin-autofix
  15. eslint-plugin-sort-keys-fix
  16. eslint-plugin-no-unsanitized
  17. @getify/eslint-plugin-proper-arrows

Typescript plugins

  1. eslint-plugin-deprecation

Angular plugins

  1. @angular-eslint/eslint-plugin

Cypress plugins

  1. eslint-plugin-cypress
  2. eslint-plugin-chai-friendly

Jest plugins

  1. eslint-plugin-jest

Json plugins

  1. eslint-plugin-jsonc
  2. jsonc-eslint-parser

Markdown plugins

  1. eslint-plugin-markdown

Plugins to check

  1. eslint-plugin-boundaries
  2. eslint-plugin-no-constructor-bind
  3. eslint-plugin-no-inferred-method-name
  4. eslint-plugin-no-secrets
  5. eslint-plugin-security
  6. eslint-plugin-xss
  7. eslint-plugin-filenames
  8. eslint-plugin-simple-import-sort
  9. eslint-plugin-switch-case
  10. eslint-plugin-const-case
  11. eslint-formatter-github
  12. eslint-nibble
  13. eslint-formatter-friendly
  14. esprint
  15. eslint-plugin-putout

Incompatible plugins

eslint-plugin-jsonc provides parser which conficlt with another libraries

eslint-plugin-jsonc provides a lot of autofixable rules, so it prefered