2.1.19 • Published 3 years ago

@clearpeaks/code-linting-style v2.1.19

Weekly downloads
52
License
ISC
Repository
github
Last release
3 years ago

Linters for standardize the code

This repo contains the different configuration files and dependencies for different linters.

Those files will be extended by the proper files of the projects, as is explained below.

Install

If you are using yarn

yarn add --dev @clearpeaks/code-linting-style

If you are using npm

npm install @clearpeaks/code-linting-style --save-dev

Git Hook

In package.json, at scripts level, add the following hook to run prettier and linter before each commit

{
  "scripts": {
    ...
  },
  "husky": {
    "hooks": {
      "pre-commit": "pretty-quick --staged && tslint -c ./tslint.json 'src/**/*.ts'"
    }
  }
}

Deprecarion warning. Upgrading from 0.14

With the version 0 the precommit hook was being declared inside of the scripts. Please change that logic on your projects.

{
  "scripts": {
    "precommit": "pretty-quick --staged && tslint -c ./tslint.json 'src/**/*.ts'"   // Before (BAD)
  },
  "husky": {
    "hooks": {
      "pre-commit": "pretty-quick --staged && tslint -c ./tslint.json 'src/**/*.ts'"    // Now (GOOD)
    }
  }
}

Note: Version 1 of husky require node version >=6, while Husky 2 require node>=8, so we are keeping husky 1 for compatibility.

Tslint

Create tslint config file

touch tslint.json

Add the following content to that file to extend from the clearpeaks package

{
  "defaultSeverity": "error",
  "extends": ["@clearpeaks/code-linting-style/tslint.js"],
  "jsRules": {
    "no-empty": true
  }
}

You can find more info about tslint rules here

Prettier

Create a prettier config file

touch .prettierrc.js

Add the following content to that file to extend from the clearpeaks package

const clearpeaksConfig = require('@clearpeaks/code-linting-style/prettier-conf');
module.exports = clearpeaksConfig;

You can find more info about prettier option/config rules here

More info about prettier configuration file here

ESLint

Create eslint config file

touch .eslintrc.js

Add the following content to that file to extend from the clearpeaks package

module.exports = {
  extends: [
    "./node_modules/@clearpeaks/code-linting-style/.eslintrc.js",
    "prettier"
    ]
}

Note: I had to use the following hook to make the precommit work

  "husky": {
    "hooks": {
      "pre-commit": "./node_modules/.bin/pretty-quick --staged && ./node_modules/.bin/eslint --ext .js lib/ --fix"
    }
  },

Installing some extra packages npm i -D eslint eslint-config-prettier husky prettier pretty-quick You can find more info about eslint rules here

Tips

If you are using prettier in vscode, you can enable autoprettify on save, to prettify you files after saving them Add the following config to the User Settings.

To avoid unwanted behaviour with prettier and html, we recommend you to disable runing prettier on save for html files

"editor.formatOnSave": true,
"prettier.eslintIntegration": true,
"[html]": {
  "editor.formatOnSave": false
},

Deploy a new version of the package

Once the PR has been approved:

  1. Increase the semver npm version <patch|minor|major> // This creates a new commit
  2. Publish the package npm publish
  3. Push autogenerated commit git push
  • Note, maybe you will need to login the first time: npm login and use the credentials of ClearPeaks

BREAKING CHANGES 2.x -> 3.x

Upgrading to 3.x version, requires to have Node.js 10+

2.1.19

3 years ago

2.1.18

4 years ago

2.1.16

4 years ago

2.1.17

4 years ago

2.1.14

4 years ago

2.1.15

4 years ago

2.1.12

4 years ago

2.1.11

4 years ago

2.1.10

4 years ago

2.1.9

4 years ago

2.1.8

4 years ago

2.1.6

4 years ago

2.1.7

4 years ago

2.1.5

5 years ago

2.1.4

5 years ago

2.1.3

5 years ago

2.1.2

5 years ago

2.1.1

5 years ago

2.1.0

5 years ago

2.0.10

6 years ago

2.0.9

6 years ago

2.0.8

6 years ago

2.0.7

6 years ago

2.0.6

6 years ago

2.0.5

6 years ago

2.0.3

6 years ago

2.0.2

6 years ago

2.0.1

6 years ago

2.0.0

6 years ago