GithubHelp home page GithubHelp logo

q-nick / eslint-config-turbocharge Goto Github PK

View Code? Open in Web Editor NEW
3.0 2.0 0.0 250 KB

The purpose of this config is to keep extremely easy to use ESLint, Typescript, and Prettier in any project.

License: MIT License

JavaScript 44.88% TypeScript 22.23% Gherkin 32.89%
eslint typescript react javascript nodejs prettier eslint-plugin code-quality

eslint-config-turbocharge's Introduction

ESLint Config Turbocharge

The purpose of this config is to keep extremely easy to use ESLint, Typescript, and Prettier in any project.

Downloads Version License

About

ESLint - this is the best tool in the world that improves your Javascript code. It acts as a guide showing you good practices and helping you to avoid unnecessary issues.

Prettier - allows you to keep your code style consistent between many environments and many projects.

Typescript - is another excellent tool that could be helpful in our daily work - this one is bringing to us static typings.

The only disadvantage of them is that they are not very easy to configure, especially if you want to connect them with React or some other framework. This project tries to solve this problem.

Table of Contents

  1. Install
  2. Setting up a basic project
  3. Setting up a React project
  4. Setting up a Node project
  5. Setting up a project with Node and React
  6. What's inside

Install

The first thing you have to do is to remove all eslint dependencies (including plugins, almost everything that contains eslint in the name) from your package.json. Now, you can install this package:

npm i --save-dev eslint-config-turbocharge

Configuration

This config contains a few presets for different kinds of projects:

  • react
  • nodejs
  • react-native (TODO)

Setting up a basic project

Let's say that you have a project structure like this and already installed eslint-config-turbocharge:

your-project
├── package.json
├── config.js
├── src
│ ├── A.ts
│ └── B.ts
└── node_modules

To enable eslint - you will need proper .eslintrc, for typescript - tsconfig.json and for prettier - .prettierrc

.eslintrc

{ "extends": "turbocharge", "root": true }

.tsconfig.json

{  "extends": "eslint-config-turbocharge/node/tsconfig.json" }

.prettierrc

"eslint-config-turbocharge/prettier"

Our example project should look like this:

your-project
├── package.json
├── .eslintrc          <== new
├── .prettierrc        <== new
├── .tsconfig.json     <== new
├── config.js
├── src
│ ├── A.ts
│ └── B.ts
└── node_modules

Now everything is set up.

Setting up a React project

We are going to use a project structure the same as for Basic setup. But now src folder will contain React components.

your-project
├── package.json
├── .eslintrc
├── .prettierrc
├── .tsconfig.json
├── config.js
├── src
│ ├── .tsconfig.json     <== new
│ ├── .eslintrc          <== new
│ ├── App.tsx
│ └── Navbar.tsx
└── node_modules

.eslintrc

{ "extends": "turbocharge/react", "root": true }

.tsconfig.json

{  "extends": "eslint-config-turbocharge/react/tsconfig.json" }

First we are going to put additional .tsconfig.json and .eslintrc files inside src folder, also with "root": true property - this is crucial.

This way we change eslint/typescript behavior only for src files. Top-level files like config.js (i.e. webpack.config.js) will not report any problems related to React rules.

Setting up a Node project

We are going to use a project structure the same as for Basic setup. But now src folder will contain Node files.

your-project
├── package.json
├── .eslintrc
├── .prettierrc
├── .tsconfig.json
├── config.js
├── src
│ ├── .eslintrc          <== new
│ ├── service.ts
│ ├── server.ts
│ └── controller.ts
└── node_modules

.eslintrc

{ "extends": "turbocharge/node", "root": true }

We just need to put .eslintrc file inside src folder, with "root": true property - this is crucial.

This way we change eslint behavior only for src files. Top-level files like config.js (i.e. webpack.config.js) will not report any problems related to Node rules.

Setting up a project with Node and React

Looking at React and Node examples, we can try to mix them up in project which contain both React and Node code.

Example project structure based on Basic project:

your-project
├── package.json
├── .eslintrc
├── .prettierrc
├── .tsconfig.json
├── config.js
├── src-backend
│ ├── .eslintrc          <==
│ ├── service.ts
│ ├── server.ts
│ └── controller.ts
├── src-frontend
│ ├── .tsconfig.json     <==
│ ├── .eslintrc          <==
│ ├── service.ts
│ ├── server.ts
│ └── controller.ts
└── node_modules

.eslintrc

{ "extends": "turbocharge/node", "root": true }

.eslintrc

{ "extends": "turbocharge/react", "root": true }

.tsconfig.json

{  "extends": "eslint-config-turbocharge/react/tsconfig.json" }

Simple as that.

Explanations

  • "root": true - makes you sure that the only config you are using is defined in that file.

What's inside

This project does not contain any new eslint-rules, it is just a set of correctly preconfigured rules of the modules that are listed below:

Common:

React:

NodeJS:

Authors and Contributors

@q-nick

eslint-config-turbocharge's People

Stargazers

 avatar  avatar  avatar

Watchers

 avatar  avatar

eslint-config-turbocharge's Issues

Setup `eslint-config-turbocharge` with VSCode ?

Hi, @q-nick thanks for maintaining this !

I had Prettier and Eslint installed globally and wired somehow with VSCode so all went well, now that I'm not the only one on the project, I want to uniform the style with other peers.

I removed (deactivated) Eslint and Prettier from VSCode (which were fulfilled from the global dependencies I believe), then installed your solution as in README.

By any chance (I know this is not only supposed to work on VSCode) how to make VSCode aware of eslint-config-turbocharge ?
Is it supposed to be used so ? or when running the apps it reports something ? You didn't specify that in README.

Thanks !!

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.