0.0.2 • Published 3 years ago

@johnpc/ts-style v0.0.2

Weekly downloads
1
License
-
Repository
-
Last release
3 years ago

@johnpc/ts-style

Set up a package using johnpc's coding style and commit conventions.

What does it do?

@johnpc/ts-style sets up the following:

Husky will run prettier and eslint on files that end with .js, .jsx, .ts, .tsx. It will run only prettier on other files that prettier supports.

It also configures a local commit template that explains conventional commits so you don't forget!

Getting Started

If you already have any of these packages installed, you'll have to remove them before installing @johnpc/ts-style, otherwise package-lock might pin them in a nested folder, and the commands won't be available to your IDE.

npm remove prettier eslint husky @commitlint/cli @commitlint/config-conventional @typescript-eslint/eslint-plugin @typescript-eslint/parser eslint-config-prettier eslint-plugin-import eslint-plugin-unicorn lint-staged

Also, as of right now, this may replace your existing eslint and prettier configs. You may want to back them up first.

First, install using npm:

npm install --save-dev @johnpc/ts-style

Next, initialize it in your package:

./node_modules/.bin/johnpc-ts-style init

That's it!

Overriding / Extending

@johnpc/ts-style adds js configs that can be replaced/overridden.

eslint

Modify the .eslintrc.js file - rules added here override rules from @johnpc/ts-style/eslint.

// .eslintrc.js
module.exports = {
  extends: ['./node_modules/@johnpc/ts-style/eslint'],
  rules: {
    // additional rules
  },
};

Note that the extends line must start with ./node_modules/. This is because eslint expects all shared config packages to start with eslint-config-. Hopefully this will be less awkward once eslint finishes their config simplification.

prettier

The .prettierrc.js file can be extended using the spread operator:

// .prettierrc.js
const config = require('@johnpc/ts-style/prettier');

module.exports = {
  ...config,
  printWidth: 120,
};