Giter Club home page Giter Club logo

eslint-config-valantic's Introduction

valantic ESLint config

To ensure a high and consistent code quality for JavaScript and TypeScript we use ESLint.

http://eslint.org

Code style

At valantic the JavaScript and TypeScript code style is based on the Airbnb JavaScript codes style for ES2015+.

https://github.com/airbnb/javascript

See package.json for currently used version.

Exceptions

We've made some internal adjustments to the code style, to meet our daily needs. See the files inside ./rules/ to learn more about these adjustments.

ESLint version

Check the required ESLint version in the package.json file. To check for updates, see http://eslint.org/blog/

Install

Use npm to install the ESLint config to your project.

Install current version

npm install eslint-config-valantic eslint eslint-plugin-import eslint-config-airbnb-base --save-dev

Setup

After installing the config package, you still need to create a .eslintrc.js inside your project, where you tell ESLint to use the valantic config.

// .eslintrc.js

module.exports ={
  extends: 'valantic',
  rules: {
    // Use for project specific settings
  }
};

Vue 2 support

If your project is based on Vue 2 you should use the vue config.

// .eslintrc.js

const vueRules = require('eslint-config-valantic/plugins/vue');

module.exports = {
  extends: [
    'valantic/vue',
  ],
}

Vue 3 support

If your project is based on Vue 3 with TypeScript you should use the vue3 config.

// .eslintrc.js

const vueRules = require('eslint-config-valantic/plugins/vue');

module.exports = {
  extends: [
    'valantic/vue3',
    '@vue/typescript',
  ],
}

NOTE: @vue/typescript is important. Else, TypeScript will not be able to parse *.vue files.

TypeScript support

If your project uses TypeScript, you need to use some additional dependencies installed:

{
  "devDependencies": {
    "@typescript-eslint/eslint-plugin": "~4.31.1",
    "@typescript-eslint/parser": "~4.31.1"
  }
}

and set the correct config that should be extended.

// .eslintrc.js
module.exports = {
  extends: [
    'valantic/typescript'
  ],
}

--fix

There is a special config if you want to use auto code styling and the --fix command. It is recommended to use this extended definition if you plan to use --fix.

  1. Add a new .eslintrc.fix.js to your project that extends the "fix" configuration. It would also be possible to define or adjust additonal rules here.
// https://eslint.org/docs/user-guide/configuring
module.exports = {
  extends: [
    'valantic/fix',
  ],
};
  1. Add a new NPM script in package.json.

**NOTE: The file loaded by --config in the eslint:fix script will EXTEND the basic configuration, NOT replace it!

{
  "eslint": "eslint --cache --ext .js,.vue src tests/unit/specs",
  "eslint:fix": "npm run eslint -- --config .eslintrc.fix.js --cache=false --fix"
}
  1. Extend GIT hooks

Finally, update the lint-staged configuration to apply auto code styling on commit.

{
  "lint-staged": {
    "*.{js,vue}": [
      "eslint --config .eslintrc.fix.js --fix"
    ],
    "*.{css,vue,scss}": [
      "stylelint"
    ]
  }
}

Use

Now you are ready to enable ESLint in your editor or use it on the command line!

PhpStorm

Go to PhpStorm > Preferences and search for ESLint or navigate to Languages & Frameworks > JavaScript > Code Quality Tools > ESLint and enable ESLint. Make sure you set the ESLint package to the one in your node_modules folder. Else the global ESLint will be used and won't be able to find the valantic config.

Console

You can also lint your code from the console. To do this, add a script to your package.json.

{
  "scripts": {
    "eslint": "eslint"
  }
}

Now you can execute the linter with the following command.

npm run eslint <app|file.js>

NOTE: don't use the $ eslint command, since this will call the global ESLint package, which will not be able to find the valantic config inside your project!

Rule hints

valid-jsdoc and PhpStorm

In case your PhpStorm is using @return instead of the required @returns: Write the return tag yourself for once and select the correct type from the suggestion list. PhpStorm will keep your last preference and use it from now on. See also https://youtrack.jetbrains.com/issue/WEB-7516#comment=27-611256

eslint-config-valantic's People

Contributors

janwidmer avatar janwidmer-work avatar patric-eberle avatar sahinu88 avatar

Stargazers

 avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

eslint-config-valantic's Issues

Add interface rules for TS

There are 2 rules that are good to have.

  1. https://typescript-eslint.io/rules/naming-convention
  2. https://typescript-eslint.io/rules/no-empty-interface

1. Naming convention

Having the I as prefix for interface names is no longer standard and should not be used anymore.

To enforce this we can add a rule to typescript.js

{
  "@typescript-eslint/naming-convention": [
    "error",
    {
      "selector": "interface",
      "format": ["PascalCase"],
      "custom": {
        "regex": "^I[A-Z]",
        "match": false
      }
    }
  ]
}

No empty interface

It should never be the case to have an empty interface. Either the interface has properties or it is not needed at all and can therefore be deleted.

To enforce this we can add a rule typescript.js

{
  "@typescript-eslint/no-empty-interface": [
    "error",
    {
      "allowSingleExtends": false
    }
  ]
}

Add/Update Rules

Add

  • no-empty-interface
  '@typescript-eslint/no-empty-interface': ['error', {
      allowSingleExtends: true,
    }],
  • explicit-function-return-type
'@typescript-eslint/explicit-function-return-type': ['error', {
      allowTypedFunctionExpressions: true,
    }],

Update

  • import/extensions
    'import/extensions': 'off'

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.