Giter Site home page Giter Site logo

kiprasmel / eslint-config-kiprasmel Goto Github PK

View Code? Open in Web Editor NEW

This project forked from wesbos/eslint-config-wesbos

5.0 1.0 3.0 394 KB

πŸ‰ ESLint v5/v7, Prettier & TypeScript setup β€” supports all environments β€” global, local, vscode, react, CRA etc.

Home Page: https://npmjs.com/eslint-config-sarpik

License: MIT License

JavaScript 100.00%
eslint prettier typescript all environments support global local vscode react sarpik

eslint-config-kiprasmel's Introduction

No-Sweatβ„’ ESLint, Prettier and TypeScript setup

These are my settings for ESLint and Prettier

You might like them - or you might not. Don't worry you can always change them.

What it does

  • Lints JavaScript based on the latest standards
  • Fixes issues and formatting errors with Prettier
  • Lints + Fixes inside of html script tags
  • Lints + Fixes React via eslint-config-airbnb
  • You can see all the rules here. You are very welcome to overwrite any of these settings, or just fork the entire thing to create your own.

Installing

You can use eslint globally and/or locally per project.

It's usually best to install this locally once per project, that way you can have project specific settings as well as sync those settings with others working on your project via git.

I also install globally so that any project or rogue JS file I write will have linting and formatting applied without having to go through the setup. You might disagree and that is okay, just don't do it then πŸ˜ƒ.

Staying up-to-date

You can watch the repo (releases only) on github to get notified once I release a new version! πŸš€

Local / Per project install

yarn init -y                                            # Create 'package.json' if you haven't already
npx install-peerdeps --dev eslint-config-kiprasmel --yarn  # Install everything needed by the config
                                                        # You can see in your package.json there's now a big list of devDependencies
touch .eslintrc.js                                      # Create the config file @ the project's root

Your .eslintrc.js file should look like this:

module.exports = {
  "extends": [
    "kiprasmel"
  ],
  "ignorePatterns": [
    "node_modules",
	"dist",
	"build",
  ],
  "rules": {},
}

Tip: You can alternatively put this object in your package.json under the property "eslintConfig": { ... }. This makes one less file in your project.

You can add these two scripts to your package.json to lint and/or fix:

"scripts": {
  "lint": "eslint .",
  "lint:fix": "eslint . --fix"
},

Now you can manually lint your code by running yarn lint (npm run lint) and fix all fixable issues with yarn lint:fix (npm run lint:fix). You probably want your editor to do this though.

Global Install

  1. First install everything needed:
npx install-peerdeps --global eslint-config-kiprasmel --yarn

(note: npx is not a spelling mistake of npm. npx comes with when node and npm are installed and makes script running easier πŸ˜ƒ (and it works automatically with yarn, too!))

  1. Then you need to make a global .eslintrc.js / .eslintrc file:

ESLint will look for one in your home directory

  • ~/.eslintrc[.js] for UNIX
  • C:\Users\<username>\.eslintrc[.js] for Windows

Your .eslintrc.js file should look like this:

module.exports = {
  "extends": [
    "kiprasmel"
  ],
  "ignorePatterns": [
    "node_modules",
	"dist",
	"build",
  ],
  "rules": {},
}
  1. To use from the CLI, you can now run eslint . or configure your editor as we show next.

Settings

If you'd like to overwrite eslint or prettier settings, you can add the rules in your .eslintrc[.js] file. The ESLint rules go directly under "rules" while prettier options go under "prettier/prettier". Note that prettier rules overwrite anything in my config (trailing comma, and single quote), so you'll need to include those as well.

module.exports = {
  "extends": [
    "eslint-config-kiprasmel",
  ],
  "ignorePatterns": [
    "node_modules",
	"dist",
	"build",
  ],
  "rules": {
    "no-console": 2,
    "prettier/prettier": [
      "error",
      {
        "trailingComma": "es5",
        "singleQuote": false,
        "printWidth": 120,
        "tabWidth": 4,
      }
    ],
  },
}

With VS Code

You should read this entire thing. Serious!

Once you have done one, or both, of the above installs. You probably want your editor to lint and fix for you. Here are the instructions for VS Code:

  1. Install the ESLint package

  2. Now we need to setup some VS Code settings via Code/File β†’ Preferences β†’ Settings. It's easier to enter these settings while editing the settings.json file, so click the {} icon in the top right corner:

{
  "editor.formatOnSave": true,

  /** disable tslint - no need! */
  "tslint.enable": false,

  "eslint.enable": true,
  "editor.codeActionsOnSave": {
    "source.fixAll": true,
    // "source.fixAll.eslint": true /** included by previous setting */
  },

  // "eslint.run": "onSave",
  "eslint.run": "onType",
  /** work as a formatter, too! */
  "eslint.format.enable": true,

  /**
   * ~~turn formatting off for JS, JSX, TS & TSX - we do this via eslint~~
   * ESLint IS the formatter now!
   * (Prettier is still in the picture, as we have configured it via eslint)
  */
  "[javascript]": {
    "editor.defaultFormatter": "dbaeumer.vscode-eslint"
  },
  "[javascriptreact]": {
    "editor.defaultFormatter": "dbaeumer.vscode-eslint"
  },
  "[typescript]": {
    "editor.defaultFormatter": "dbaeumer.vscode-eslint"
  },
  "[typescriptreact]": {
    "editor.defaultFormatter": "dbaeumer.vscode-eslint"
  },

  /**
   * Optional but IMPORTANT:
   * If you have the prettier extension enabled for other languages like CSS and HTML,
   * turn it off for JS since we are doing it through eslint already
  */
  "prettier.disableLanguages": ["javascript", "javascriptreact", "typescript", "typescriptreact"],

  /** ~~make sure both js and ts are validated~~ no longer needed as of vscode-eslint 2.0 */
//   "eslint.validate": [
//     "javascript",
//     "javascriptreact",
//     "typescript",
//     "typescriptreact",
//   ]
}

See also the README of vscode-eslint.

With Create React App

Run this:

npx install-peerdeps eslint-config-kiprasmel --dev --yarn

sed 's/"react-app"/"eslint-config-kiprasmel"/g' package.json -i
sed 's/"eslint": "5.x"/"eslint": "7.x"/g'    package.json -i

yarn install

# verify
node node_modules/.bin/eslint --version

# run
eslint . --fix

# run in typescript project
eslint . --ext js,jsx,ts,tsx --fix

Your package.json should have this:

{
	"scripts": {
		"lint": "    eslint . --ext js,jsx,ts,tsx",
		"lint:fix": "eslint . --ext js,jsx,ts,tsx --fix"
	},
	"devDependencies": {
		"eslint": "7.x"
	},
	"eslintConfig": {
		"extends": [
		  "eslint-config-kiprasmel"
		],
		"ignorePatterns": [
		  "node_modules",
		  "dist",
		  "build"
		],
		"rules": {
		  "no-console": 2,
		  "prettier/prettier": [
			"error",
			{
			  "trailingComma": "es5",
			  "singleQuote": false,
			  "printWidth": 120,
			  "tabWidth": 4
			}
		  ]
		}
	}
}

Example repo with commits as setting up steps: https://github.com/kiprasmel/cra-eslint-ts

🀬🀬🀬🀬 IT'S NOT WORKING

Start fresh. Sometimes global modules can goof you up. This will remove them all:

yarn global remove eslint-config-kiprasmel @typescript-eslint/parser @typescript-eslint/eslint-plugin typescript eslint eslint-config-prettier eslint-config-airbnb eslint-plugin-html eslint-plugin-prettier eslint-plugin-import eslint-plugin-jsx-a11y eslint-plugin-react prettier eslint-plugin-react-hooks

To do the above for local, omit the --global flag.

Then if you are using a local install, remove your package-lock.json / yarn.lock file and delete the node_modules/ directory.

rm package-lock.json
rm yarn.lock
rm -rf node_modules

Then follow the above instructions again.

License

MIT Β© 2019 Kipras Melnikovas

eslint-config-kiprasmel's People

Contributors

kiprasmel avatar wesbos avatar zaklaughton avatar dependabot[bot] avatar 0xflotus avatar arapl3y avatar thebrandonallen avatar endormi avatar geoangelotti avatar johanquiroga avatar nickymeuleman avatar vpicone avatar gillkyle avatar

Stargazers

Qdigital avatar Kahlil Whitfield avatar Stephen Howells avatar  avatar Oleksandr Kovalov avatar

Watchers

 avatar

eslint-config-kiprasmel's Issues

Configuration for rule "no-unused-vars" is invalid

When using the eslint-config-sarpik with the latest version of cra typescript, the commands yarn start and yarn build give this error:

.eslintrc.js Β» eslint-config-sarpik:
Configuration for rule "no-unused-vars" is invalid:
Value {"ignoreSiblings":true,"argsIgnorePattern":"res|next|^err"} should be equal to one of the allowed values.
Value {"ignoreSiblings":true,"argsIgnorePattern":"res|next|^err"} should NOT have additional properties.
Value {"ignoreSiblings":true,"argsIgnorePattern":"res|next|^err"} should match exactly one schema in oneOf.

overriding the rule on my .eslintrc does not change the error

{
  "no-unused-vars": [
    1,
    {
      "ignoreSiblings": true,
      "argsIgnorePattern": "res"
    }
  ]
}

The package.json is

"eslintConfig": {
    "extends": [
      "react-app",
      "react-app/jest",
      "sarpik"
    ]
  },
"dependencies": {
    "@testing-library/jest-dom": "^5.11.4",
    "@testing-library/react": "^11.1.0",
    "@testing-library/user-event": "^12.1.10",
    "@types/jest": "^26.0.15",
    "@types/node": "^12.0.0",
    "@types/react": "^16.9.53",
    "@types/react-dom": "^16.9.8",
    "axios": "^0.21.0",
    "bootstrap": "^4.5.3",
    "node-sass": "4.14.1",
    "react": "^17.0.1",
    "react-dom": "^17.0.1",
    "react-router-dom": "^5.2.0",
    "react-scripts": "4.0.0",
    "react-webcam-barcode-scanner": "^0.0.2-rc2",
    "reactstrap": "^8.7.1",
    "typescript": "3.7.3",
    "web-vitals": "^0.2.4"
  },
"devDependencies": {
    "@types/react-router-dom": "^5.1.6",
    "@types/reactstrap": "^8.7.2",
    "@typescript-eslint/eslint-plugin": "2.11.0",
    "@typescript-eslint/parser": "2.11.0",
    "babel-eslint": "10.0.3",
    "eslint": "6.8.0",
    "eslint-config-airbnb": "18.0.0",
    "eslint-config-prettier": "6.7.0",
    "eslint-config-sarpik": "0.2.8",
    "eslint-plugin-flowtype": "4.5.2",
    "eslint-plugin-html": "6.0.0",
    "eslint-plugin-import": "2.18.0",
    "eslint-plugin-jsx-a11y": "6.2.3",
    "eslint-plugin-monorepo": "0.2.1",
    "eslint-plugin-prettier": "3.0.1",
    "eslint-plugin-react": "7.14.2",
    "eslint-plugin-react-hooks": "2.3.0",
    "esprima": "4.0.1",
    "prettier": "1.16.4"
  }

node version: v14.15.0
npm version: 6.14.8

React (CRA) broken with eslint `5.x` (manual work-around available)

Issue originally reported by @okovalov πŸ”₯

I will:

  • attempt upgrading eslint to 6.x.
    Previously I've had numerous issues with the v6; it's time to try again.

  • upgrade eslint to 6.x in this config

  • take care of related dependencies to match the upgraded version of eslint.


Edit:

Manual work-around: #3 (comment):

  • upgrade eslint to 6.x in your react app manually, and
  • append --ext js,jsx,ts,tsx every time you call eslint, since v6 seems to require it -- see #4

See also https://github.com/sarpik/eslint-config-sarpik#with-create-react-app

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    πŸ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. πŸ“ŠπŸ“ˆπŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❀️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.