Search
 
SCRIPT & CODE EXAMPLE
 

JAVASCRIPT

Vs Code Setup for Reactjs Project

Linting Setup

In order to lint and format your React project automatically according to popular airbnb style guide, I recommend you to follow the instructions below.
Install Dev Dependencies

yarn add -D prettier
yarn add -D babel-eslint
npx install-peerdeps --dev eslint-config-airbnb
yarn add -D eslint-config-prettier eslint-plugin-prettier

or You can also add a new script in the scripts section like below to install everything with a single command:

scripts: {
    "lint": "yarn add -D prettier && yarn add -D babel-eslint && npx install-peerdeps --dev eslint-config-airbnb && yarn add -D eslint-config-prettier eslint-plugin-prettier"
}

and then simply run the below command in the terminal -

yarn lint #or 'npm run lint'

Create Linting Configuration file manually

Create a .eslintrc file in the project root and enter the below contents:
{
  "extends": [
    "airbnb",
    "airbnb/hooks",
    "eslint:recommended",
    "prettier",
    "plugin:jsx-a11y/recommended"
  ],
  "parser": "babel-eslint",
  "parserOptions": {
    "ecmaVersion": 8
  },
  "env": {
    "browser": true,
    "node": true,
    "es6": true,
    "jest": true
  },
  "rules": {
    "react/react-in-jsx-scope": 0,
    "react-hooks/rules-of-hooks": "error",
    "no-console": 0,
    "react/state-in-constructor": 0,
    "indent": 0,
    "linebreak-style": 0,
    "react/prop-types": 0,
    "jsx-a11y/click-events-have-key-events": 0,
    "react/jsx-filename-extension": [
      1,
      {
        "extensions": [".js", ".jsx"]
      }
    ],
    "prettier/prettier": [
      "error",
      {
        "trailingComma": "es5",
        "singleQuote": true,
        "printWidth": 100,
        "tabWidth": 4,
        "semi": true,
        "endOfLine": "auto"
      }
    ]
  },
  "plugins": ["prettier", "react", "react-hooks"]
}


    e the below json in the newly created settings.json file and save the file.

{
  // Theme
  "workbench.colorTheme": "Dracula",

  // config related to code formatting
  "editor.defaultFormatter": "esbenp.prettier-vscode",
  "editor.formatOnSave": true,
  "[javascript]": {
    "editor.formatOnSave": false,
    "editor.defaultFormatter": null
  },
  "[javascriptreact]": {
    "editor.formatOnSave": false,
    "editor.defaultFormatter": null
  },
  "javascript.validate.enable": false, //disable all built-in syntax checking
  "editor.codeActionsOnSave": {
    "source.fixAll.eslint": true,
    "source.fixAll.tslint": true,
    "source.organizeImports": true
  },
  "eslint.alwaysShowStatus": true,
  // emmet
  "emmet.triggerExpansionOnTab": true,
  "emmet.includeLanguages": {
    "javascript": "javascriptreact"
  }
}

If you followed all previous steps, the theme should change and your editor should be ready.
Comment

PREVIOUS NEXT
Code Example
Javascript :: get element by id angular 
Javascript :: smooth scroll jquery 
Javascript :: mongoose update array push multiple 
Javascript :: how to write to a file with javascript without nodejs 
Javascript :: js random seed 
Javascript :: discord.js purge 
Javascript :: function in javascript 
Javascript :: angular architecture patterns 
Javascript :: best way to filter table in angular 
Javascript :: console log all array values node 
Javascript :: array example 
Javascript :: running webpack application on production server 
Javascript :: javascript array length 
Javascript :: javascript promise methods 
Javascript :: add multiple images inside the DOM js 
Javascript :: how to get a random item from an array javascript 
Javascript :: julia function 
Javascript :: discord.js add role command 
Javascript :: react.createref 
Javascript :: in express how do you set the location header 
Javascript :: javascript prompt on window close 
Javascript :: solid in css 
Javascript :: Detect Mobile / Computer by Javascript 
Javascript :: top bar in react js 
Javascript :: run promise one by one 
Javascript :: JSON to Ruby Hash Parser 
Javascript :: const justCoolStuff = (arr1, arr2) = arr1.filter(item = arr2.includes(item)); 
Python :: pandemonium 
Python :: number table python 
Python :: transform size of picture pygame 
ADD CONTENT
Topic
Content
Source link
Name
5+4 =