Git Product home page Git Product logo

front-linter's Introduction

front-linter NPM Version NPM Downloads

CLI to lint your code and make it compliant.

It provides:

  • Same js, ts and sass style of code across for all my repos.
  • Linting rules a reference package, not duplicated linting config in every project.
  • Implemented as a reusable CLI.

This package is a fork of SUI, version 2.20.0

Installation

$ npm install @rogal/front-linter --save-dev

CLI

When installed, a new CLI front-linter is automatically available to lint your files according to the conventions.

Lint JS files

$ front-linter js [options]

It lints all js|jsx|ts|tsx files in your project, excluding .eslintignore and .gitignore file patterns.

Same options available in eslint except one: -c, --config. If you try to use this option, an exception will be thrown.

Format JS/TS files

$ front-linter js --fix [options]

Lint SASS files

$ front-linter sass [options]

Lints all **/src/**/*.scss files in the project, excluding node_modules, lib, dist, public.

.gitignore file patterns are also excluded but interpretation may differ as only glob patterns are understood

Presets

Now we have three presets.

We have 3 presets: default, typescript y react

You can combine react with default or typescript

$ front-linter js -- --presets=default,react
$ front-linter js -- --presets=typescript,react

Scope commands to staged files

$ front-linter js --staged
$ front-linter js --fix --staged

Same command but applied only on staged files (obtained with git diff --cached --name-only --diff-filter=d command).

For integrations, prettier config is located in @rogal/front-linter/lint/.prettierrc.js.

Add fixes to the stage

$ front-linter js --staged --add-fixes
$ front-linter js --fix --staged --add-fixes

This option can only be used with --staged.

In fix mode like with front-linter js --fix, the --add-fixes option will stage the files again (git add <file...>)

It's usefull to make your code autoformat before any commit.

IDE JS & SASS integration

Steps to integrate front-linter with an IDE:

  1. Install (if needed) eslint/stylelint plugin in your IDE.
  2. Add these lines to package.json:
{
  "eslintConfig": {
    "extends": ["./node_modules/@rogal/front-linter/eslint-react.js"]
  },
  "stylelint": {
    "extends": [
      "./node_modules/@rogal/front-linter/.stylelintrc.js"
    ]
  }
}

IDE TS & SASS integration

Steps to integrate front-linter with an IDE:

  1. Install (if needed) eslint/stylelint plugin in your IDE.
  2. Add these lines to package.json:
{
  "eslintConfig": {
    "extends": ["./node_modules/@rogal/front-linter/eslint-react.js"]
  },
  "stylelint": {
    "extends": [
      "./node_modules/@rogal/front-linter/.stylelintrc.js"
    ]
  }
}

Example JS & SASS package.json

{
  "name": "test-project",
  "version": "1.0.0",
  "scripts": {
    "lint:js": "front-linter js",
    "lint:sass": "front-linter sass"
  },
  "eslintConfig": { "extends": ["./node_modules/@rogal/front-linter/eslint.js"] },
  "stylelint": {
    "extends": [
      "./node_modules/@rogal/front-linter/.stylelintrc.js"
    ]
  }
}

Example TS & SASS package.json

{
  "name": "test-project",
  "version": "1.0.0",
  "scripts": {
    "lint:ts": "front-linter js -- --presets=typescript",
    "lint:sass": "front-linter sass"
  },
  "eslintConfig": { "extends": ["./node_modules/@rogal/front-linter/eslint.js"] },
  "stylelint": {
    "extends": [
      "./node_modules/@rogal/front-linter/.stylelintrc.js"
    ]
  }
}

VSCode and prettier

Prettier is integrated in front-linter thanks to specific eslint rules. If you want VSCode to format your code exactly as front-linter js --fix would do, you need specific config.+

prettier + eslint

If you have installed prettier in VSCode you can launch it with CMD + Shift + P -> Format Document over an opened file to format it with prettier

By adding this line to your settings

{
  "prettier.eslintIntegration": true
}

when you do CMD + Shift + P -> Format Document the format tool will use prettier-eslint^[prettier-eslint is a dependency of prettier-vscode] that will do a eslint --fix after formatting your JavaScript file with prettier

So this shortcut will format our files ( w/ prettier) according to our front-linter rules

you will need the eslintConfig property added to the package.json as explained above

eslint extension

Install VSCode ESLint extension, and set eslint.autoFixOnSave to true:

{
  "eslint.autoFixOnSave": true
}

Conflict with formatOnSave

If you have prettier enabled, or the default VSCode formatter activated with editor.formatOnSave to true, it may conflict with the eslint.autoFixOnSave option.

{
  "editor.formatOnSave": true,
  "[javascript]": {
    "editor.formatOnSave": false,
  },
}

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.