Code Monkey home page Code Monkey logo

eslint-documentation's Introduction

๐Ÿ‘‹ Hello, I'm Anisul Islam

A full time content creator on & web developer

website youtube facebook linkedin


ESLint

1. What is ESLint?

  • A linter - tool for identifying and reporting programmatic, stylistic errors.
  • ESLint does static error checking before running the program

2. Example of Popular Linters

3. Prerequisities for setting up ESLint

  • install Node.js
  • install VSCode (as we will use VSCode)

4. Installing & using ESLint

  1. Create package.json: npm init

  2. Install and configure eslint as dev dependency: npm init @eslint/config

  3. Initialize eslint: eslint --init and follow steps:

    • How would you like to use ESLint? To check syntax and find problems
    • How would you like to use ESLint? None of these
    • How would you like to use ESLint? None of these
    • Does your project use TypeScript? โ€บ No
    • Where does your code run? Browser
  4. Go to .eslintrc.json file and make add your necessary adjustments Example

    following codes will activate the recommended rules which can be changed inside the rules object.
      {
       "extends": "eslint:recommended"
      }
    
     <!-- first value is error level, it can have 3 values: off/0, warn/1, error/2 -->
     Example of ESLint rules
     "rules": {
         "quotes": ["error", "double"]
     }
    
     More Examples of ESLint rules
    "rules": {
        "no-var": "error",
        "eqeqeq": "error",
        "no-unused-vars": "error",
        "default-case": "error",
        "no-console": "error",
        "camelcase": "error",
        "consistent-return": "error",
        "func-style": "error",
        "max-depth": ["error", 2],
        "max-lines": ["error", 25],
        "prefer-arrow-callback": "error",
        "prefer-const": "error",
        "no-useless-return": "error",
        "no-plusplus": "error",
        "quotes": ["error", "single"]
      }
    
  5. add some codes in a js file for testing the eslint. I have created a file called app.js and added the following codes for testing purpose

    var username = "anisul Islam";
    var password = "12345";
    var occupation = "full stack web developer";
    const user_presentaddress = "lala";
    
    var a = 6;
    a++;
    
    console.log(occupation);
    
    const validateUser = (pwd) => {
      if (password == pwd) {
        return true;
      }
    };
    
    console.log(validateUser(12345));
    
    switch (foo) {
      case 1:
        console.log(foo);
        break;
    
      case 2:
        console.log(foo);
        break;
    }
    
    const foo = true;
    if (foo) {
      if (foo) {
        if (foo) {
          console.log("hi");
        }
        console.log("hi");
      }
      console.log("hi");
    }
    
    setTimeout(function () {}, 1000);
  6. make some changes in setting.json

    format on save and validate js codes: add the following codes in settings.json

     "editor.codeActionsOnSave": {
     "source.fixAll.eslint": true
     },
     "eslint.validate": ["javascript"]
    
  7. Run the eslint: eslint fileName.js and check the erros

  8. Fix automatically fixable errors: eslint fileName.js --fix


Thanks for reading this documentation. keep following me.


eslint-documentation's People

Contributors

anisul-islam 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.