1.0.4 • Published 1 year ago

eslint-config-kenect v1.0.4

Weekly downloads
-
License
-
Repository
-
Last release
1 year ago

eslint-config-kenect

Project Install

  1. install this config
npm install eslint-config-kenect
  1. We need to put our eslint settings in a file in the root of your project.

in package.json, add this anywhere top level. Like right under your "scripts" object.

"eslintConfig": {
  "extends": ["kenect"]
}

Or put this in a .eslintrc file

{
  "extends": ["kenect"]
}

For TypeScript projects, use kenect/typescript.

{
  "extends": ["kenect/typescript"]
}

TypeScript repos will also need a tsconfig.json file in their project. An empty object ({}) will do!

  1. You can add two scripts to your package.json to lint and/or fix:
"scripts": {
  "lint": "eslint .",
  "lint:fix": "eslint . --fix"
},
  1. Done! You can now use the CLI to lint and fix files.

Settings

If you'd like to overwrite eslint or prettier settings, you can add the rules in your .eslintrc file. The ESLint rules go directly under "rules".

{
  "extends": [
    "kenect"
  ],
  "rules": {
    "no-console": 2,
  }
}

With VS Code

  1. Install the ESLint package
  2. Now we need to setup some VS Code settings via Code/FilePreferencesSettings. It's easier to enter these settings while editing the settings.json file, so click the Open (Open Settings) icon in the top right corner:
"editor.formatOnSave": true,
// turn it off for JS and JSX, we will do this via eslint
"[javascript][javascriptreact][typescript][typescriptreact]": {
  "editor.formatOnSave": false
},
// tell the ESLint plugin to run on save
"editor.codeActionsOnSave": {
  "source.fixAll": true
}

After attempting to lint your file for the first time, you may need to click on 'ESLint' in the bottom right and select 'Allow Everywhere' in the alert window.

Finally you'll usually need to restart VS code. They say you don't need to, but it's never worked for us until we restart.

With JetBrains Products (IntelliJ IDEA, WebStorm, RubyMine, PyCharm, PhpStorm, etc)

If you have previously configured ESLint to run via a File Watcher, you might want to turn that off.

Issues with ESLint not formatting code

If you experience issues with ESLint not formatting the code or you receive a Parsing error: Cannot find module '@babel/preset-react error message then you need to check that you opened the folder where you installed and configured ESLint directly in VS Code. The correct folder to open will be the one where you installed the eslint-config-kenect npm package and where you created the .eslintrc file.

Opening a parent folder or child folder in your code editor will cause ESLint to fail in finding the ESLint npm packages and the formatting won't work.

your-username
  |
  work_projects
    |
    platform-ui # <- Open this folder directly in your code editor
      client/
      node_modules/
      server/
      .eslintrc
      package.json