# @rogal/front-linter

> Linting CLI for Frontend Projects

Latest version **3.0.0-beta.9** (published 2021-02-04) · MIT license · 0 weekly downloads

## Install

```sh
npm install @rogal/front-linter
pnpm add @rogal/front-linter
yarn add @rogal/front-linter
bun add @rogal/front-linter
```

Provides the command `front-linter`.

## Health

**Score 15/100 (F)** — status: abandoned.

Positive: no vulnerabilities.

Warnings: low downloads; no types; no esm support.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 3.0.0-beta.9 |
| Published | 2021-02-04 |
| First published | 2019-01-20 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 20 |
| Unpacked size | 65.1 KB |
| Known vulnerabilities | 0 (+8 in 1 direct dependencies) |
| Install scripts | no |
| Maintainers | gabrielseco |

## Links

- npm: https://www.npmjs.com/package/@rogal/front-linter
- npm.io page: https://npm.io/package/@rogal/front-linter

## Dependencies (20)

- [colors](https://npm.io/package/colors.md) 1.4.0
- [eslint](https://npm.io/package/eslint.md) 7.19.0
- [figures](https://npm.io/package/figures.md) 2.0.0
- [prettier](https://npm.io/package/prettier.md) 2.2.1
- [commander](https://npm.io/package/commander.md) 2.15.1
- [stylelint](https://npm.io/package/stylelint.md) 13.9.0
- [simple-git](https://npm.io/package/simple-git.md) 1.92.0
- [babel-eslint](https://npm.io/package/babel-eslint.md) 10.1.0
- [stylelint-scss](https://npm.io/package/stylelint-scss.md) 3.18.0
- [eslint-plugin-react](https://npm.io/package/eslint-plugin-react.md) 7.22.0
- [eslint-plugin-import](https://npm.io/package/eslint-plugin-import.md) 2.22.1
- [eslint-config-prettier](https://npm.io/package/eslint-config-prettier.md) 7.2.0
- [eslint-plugin-jsx-a11y](https://npm.io/package/eslint-plugin-jsx-a11y.md) 6.4.1
- [eslint-plugin-prettier](https://npm.io/package/eslint-plugin-prettier.md) 3.3.1
- [eslint-plugin-react-perf](https://npm.io/package/eslint-plugin-react-perf.md) 3.3.0
- [@typescript-eslint/parser](https://npm.io/package/@typescript-eslint/parser.md) 4.14.2
- [eslint-plugin-react-hooks](https://npm.io/package/eslint-plugin-react-hooks.md) 4.2.0
- [@typescript-eslint/eslint-plugin](https://npm.io/package/@typescript-eslint/eslint-plugin.md) 4.14.2
- [stylelint-config-sass-guidelines](https://npm.io/package/stylelint-config-sass-guidelines.md) 7.1.0
- [stylelint-declaration-use-variable](https://npm.io/package/stylelint-declaration-use-variable.md) 1.7.2

## Recent versions

- 3.0.0-beta.9 (latest) — 2021-02-04
- 4.0.0-beta.8 (beta) — 2023-01-15
- 4.0.0-beta.7 — 2023-01-15
- 4.0.0-beta.6 — 2022-01-23
- 4.0.0-beta.5 — 2022-01-23
- 4.0.0-beta.4 — 2022-01-22
- 4.0.0-beta.3 — 2021-06-11
- 4.0.0-beta.2 — 2021-06-09
- 4.0.0-beta.1 — 2021-03-27
- 4.0.0-beta.0 — 2021-03-27
- 3.0.0-beta.10 — 2021-03-27
- 3.0.0-beta.8 — 2020-12-05
- 3.0.0-beta.7 — 2020-11-08
- 3.0.0-beta.6 — 2020-08-11
- 3.0.0-beta.5 — 2020-07-14
- … 27 more at https://npm.io/package/@rogal/front-linter/versions

## README

# front-linter [![NPM Version](https://img.shields.io/npm/v/@rogal/front-linter.svg)](https://www.npmjs.com/package/@rogal/front-linter) [![NPM Downloads](https://img.shields.io/npm/dm/@rogal/front-linter.svg)](https://www.npmjs.com/package/@rogal/front-linter)

> 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](https://github.com/SUI-Components/sui/blob/master/packages/sui-lint), version 2.20.0

## Installation

```sh
$ 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

```sh
$ front-linter js [options]
```

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

Same options available in [eslint](https://eslint.org/docs/user-guide/command-line-interface) except one: `-c, --config`. If you try to use this option, an exception will be thrown.



### Format JS files

```sh
$ front-linter js --fix [options]
```


### Lint Typescript files 
```sh
$ front-linter js -- --presets=typescript [options]
```

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

Same options available in [eslint](https://eslint.org/docs/user-guide/command-line-interface) except one: `-c, --config`. If you try to use this option, an exception will be thrown.

For typescript you'll need to install the **eslint-import-resolver-typescript**

```js
  npm i --save-dev eslint-import-resolver-typescript
```

### Format TS files

```sh
$ front-linter  -- --presets=typescript --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.

You have the preset javascript, typescript and react

You can combine react with javascript or typescript with react

```sh
$ front-linter js -- --presets=javascript,react
```

```sh
$ front-linter js -- --presets=typescript,react
```


### Scope commands to staged files

```sh
$ 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

```sh
$ 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`:

```json
{
  "eslintConfig": {
    "extends": ["./node_modules/@rogal/front-linter/javascript-react-eslint.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`:

```json
{
  "eslintConfig": {
    "extends": ["./node_modules/@rogal/front-linter/typescript-react-eslint.js"]
  },
  "stylelint": {
    "extends": [
      "./node_modules/@rogal/front-linter/.stylelintrc.js"
    ]
  }
}
```

### Example JS & SASS package.json

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

### Example TS & SASS package.json

```json
{
  "name": "test-project",
  "version": "1.0.0",
  "scripts": {
    "lint:ts": "front-linter js -- --presets=typescript",
    "lint:sass": "front-linter sass"
  },
  "devDependencies": {
    "@rogal/front-linter": "1.0.0"
  },
  "eslintConfig": { "extends": ["./node_modules/@rogal/front-linter/typescript-react-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](https://marketplace.visualstudio.com/items?itemName=esbenp.prettier-vscode) you can launch it with `CMD + Shift + P -> Format Document` over an opened file to format it with [prettier](https://github.com/prettier/prettier)

By adding this line to your settings 

```json
{
  "prettier.eslintIntegration": true
}
```

when you do `CMD + Shift + P -> Format Document` the format tool will use [`prettier-eslint`](https://github.com/prettier/prettier-eslint)^[`prettier-eslint` is a dependency of [prettier-vscode](https://github.com/prettier/prettier-vscode/blob/1843acb5defac7898862a1df61cb67c7a8355d69/package.json#L204)] that will do a [`eslint --fix`](http://eslint.org/) after formatting your JavaScript file with [`prettier`](https://github.com/prettier/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](https://marketplace.visualstudio.com/items?itemName=dbaeumer.vscode-eslint), and set `eslint.autoFixOnSave` to true:

```json
{
  "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.

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

---
_Source: https://npm.io/package/@rogal/front-linter · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
