Coder Social home page Coder Social logo

eslint-config-sprylab's Introduction

Eslint Config Sprylab

This is an eslint config used at Sprylab GmbH for typescript, react and react-native based projects.

Installation

yarn add --dev @sprylab/eslint-config

or

npm i --save-dev @sprylab/eslint-config

Also make sure to have prettier and of course typescript and eslint installed as well. Then add the following config to your extend array in your eslint config file.

module.exports = {
    extends: [
        '@sprylab/eslint-config', // this is the base
        /* 
            for react: '@sprylab/eslint-config/react'
            for native: '@sprylab/eslint-config/native'
        */
    ],
    parserOptions: {
        project: './tsconfig.json', // should be the path to the projects tsconfig.json
    },
}

IMPORTANT:

  • For this config to work you need to have a tsconfig.json file at the repo root level, and then you have to set the parserOptions.project to point to your tsconfig file. see the @typescript-eslint plugin docs.
  • You also need to have babel installed and a babel config file at the repo root level see the @babel eslint parser docs
  • for best experience you should have a prettier config file at the repo root as well, otherwise the eslint-config-prettier will use its builtin defaults.
  • if you use path aliases, (e.g. use "@" as a path alias to /src etc.), you will probably need to setup a path resolver for the eslint-plugin-import package or turn off some of its rules. There is a resolver for node, typescript, babel, webpack etc.

Configuration

This package includes three distinct configs:

base

  • @typescript, @babel, es2021 globals and testing-library.
extends: [
    '@sprylab/eslint-config',
],

react

  • base config, browser globals, react, react-hooks and testing-library/react.
extends: [
    '@sprylab/eslint-config/react',
]

native

  • native -> react config + react native
extends: [
    '@sprylab/eslint-config/native',
]

Plugins included

This config includes and configures the following eslint plugins / parsers:

Parsers

For javascript files (*.js(x)):

  • @babel/eslint-parser
  • @babel/eslint-plugin

For typescript files only (*.ts(x)):

  • @typescript-eslint/eslint-plugin
  • @typescript-eslint/parser

Plugins

Base

plugins shared by all configs / overrides

  • eslint-config-prettier
  • eslint-plugin-prettier
  • eslint-plugin-import
  • eslint-plugin-sonarjs
  • eslint-plugin-sort-imports-es6-autofix

Testing

plugins shared across all configs for test files (example.spec.ts) etc.)

  • eslint-plugin-testing-library
  • eslint-plugin-jest

Non-Testing

  • eslint-plugin-unicorn

React and React Native

  • eslint-plugin-react
  • eslint-plugin-react-hooks

React (exclusive)

  • plugin:jsx-a11y/recommended

React Native (exclusive)

  • eslint-plugin-react-native

Recommendations

  • add a pre-commit eslint check using husky and lint-staged to your package.json file, for example:
"husky": {
    "hooks": {
        "pre-commit": "lint-staged"
    }
},
"lint-staged": {
    "*.{md,json,yml,yaml}": [
        "prettier --write"
    ],
    "*.{jsx,jsx,ts,tsx}": [
        "eslint --fix"
    ]
}
  • add package.json eslint scripts:
"scripts": {
    "check:script": "eslint --fix-dry-run './{src,__tests__}/**/*.{js,ts,tsx}'",
    "lint:script": "eslint --fix './{src,__tests__}/**/*.{js,ts,tsx}'",
}

eslint-config-sprylab's People

Contributors

schwarzkopfb avatar goldziher avatar

Watchers

James Cloos avatar

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.