0.11.0 • Published 9 months ago

eslint-plugin-banno-prism v0.11.0

Weekly downloads
-
License
Apache-2.0
Repository
github
Last release
9 months ago

eslint-plugin-banno-prism

This is an ESLint plugin for Banno Prism projects.

🚨 This plugin is not ready yet! See the Roadmap below. 🚨

  • At this time only Typescript projects are supported.
  • It's fairly strict. It's based on Standard and enforces certain styles.

Please open an issue (Jack Henry developers can discuss in #org-prism) for any questions or requests. PRs are welcome.

Requirements

  • Node.js >=12.22.0

Using in Your Project

Installation

(Script provided at the bottom to role all of these steps into one.)

You'll first need to install our ESLint plugin using some of ESLint's rules:

yarn add eslint-plugin-banno-prism lint-staged husky --dev

You also will want an easy way to download all the peer dependencies. To do that:

yarn add install-peerdeps --dev

Then to run the newly installed package to download the dependencies using yarn:

npx install-peerdeps eslint-plugin-banno-prism --dev --yarn

Configuration

Create an eslint configuration file (e.g. .eslintrc.js) in your project folder. Include this plugin and choose a ruleset to extend:

module.exports = {
  root: true,
  parserOptions: {
    project: 'tsconfig.dev.json'
  },
  plugins: [
    'banno-prism'
  ],
  extends: [
    'plugin:banno-prism/typescript'
  ],
  settings: {
    'import/resolver': {
      node: {
        'extensions': ['.js', '.ts']
      }
    }
  }
}

The plugin offers the following configurations:

  • typescript -- Includes rules for existing projects, mostly these rules will autofix, or be able to be otherwise applied in bulk
  • typescript-strict -- Includes rules that are good but don't autofix and can be too much for existing projects

You'll probably want to use or create a different tsconfig file to include files beyond what is included in the tsconfig.json file (e.g. test files, miscellaneous scripts):

{
  "extends": "./tsconfig.json",
  "include": [
    "src/types",
    "src/**/*.ts",
    "test/**/*.ts"
  ]
}

Note that strictNullChecks must be enabled in your tsconfig file. Otherwise @typescript-eslint/no-unnecessary-boolean-literal-compare will not work correctly.

You can include the only-warn plugin to convert all errors to warnings. This is useful for established projects that need to be linted but shouldn't block commits or CI pipelines.

In package.json add the lint-staged config:

  "lint-staged": {
    "*.{js,ts}": "eslint --max-warnings=0"
  },

You'll also want to double check that the engine for node is defined so the node rules work correctly:

  "engines": {
    "node": "18.x"
  },

Add the husky scripts to run lint-staged pre-commit by executing:

npm pkg set scripts.prepare="husky install"
npm run prepare
npx husky add .husky/pre-commit "npx lint-staged"
git add .husky/pre-commit

Add these scripts to package.json

    "lint": "eslint --max-warnings=0 src/ test/",
    "lint:ci": "eslint --max-warnings=0 src/ test/",
    "lint:fix": "eslint --fix src/ test/",

You can do pretty much everything above (expect tsconfig edits which may not be needed) with the script below (note you'll need to fix the cp command to copy from some valid eslintrc file)

npm pkg set "lint-staged[*.{js,ts}]"="eslint --max-warnings=0" && npm pkg set engines.node="18.x" && yarn add @typescript-eslint/eslint-plugin eslint-plugin-banno-prism lint-staged husky eslint eslint-config-standard@^17 eslint-plugin-import@^2.27.5 --dev && npm pkg set scripts.prepare="husky install" && npm run prepare && npx husky add .husky/pre-commit "npx lint-staged" && cp /Users/loren/Sites/node-links-aggregator/.eslintrc.cjs ./ && rm -f tslint.json && npm pkg set scripts.lint="eslint --max-warnings=0 src/ test/" && npm pkg set scripts.lint:fix="eslint --fix src/ test/" && npm pkg set scripts.lint:ci="eslint --max-warnings=0 src/ test/" && git add .husky/pre-commit package.json yarn.lock .eslintrc.cjs && yarn remove tslint tslint-config-standard

If your project uses binci.yml, you'll want to add yarn lint:ci as the first part of binci test.

Usage

Run ESLint against the files and folders you want to check:

eslint --fix bin/ src/ test/

Include the --fix flag to automatically fix problems.

Notes

eslint-plugin-n replaces the eslint-plugin-node plugin.

You can disable an eslint rule for a block of code (function, file, etc) by putting /* eslint-disable <rule-name> */ above the code to be executed. Putting this at the top of the file will ignore the whole file for the given rule.

Roadmap

v0.x.0

The v0.x.0 series will be used while the plugin is under active development and rules are being ironed out.

Most rules will be set as warnings to allow for testing without blocking CI.

  • Get basic plugin working and published for usage
  • First pass of rules (sanity check, discussion)

v1.0.0

Starting with v1.0.0, the plugin is ready for primetime.

Linting problems that should be fixed prior to commit will be emitted as errors.

post v1.0.0