Meet npm Pro: unlimited public & private packages + package-based permissions.Learn more »

@fimbul/heimdall

0.21.0 • Public • Published

Heimdall

Wotan module to use TSLint rules and formatters.

npm version npm downloads Renovate enabled CircleCI Build status codecov Join the chat at https://gitter.im/fimbullinter/wotan

Make sure to also read the full documentation of all available modules.

Purpose

Enable the use of TSLint rules and formatters.

Installation

npm install --save-dev @fimbul/wotan @fimbul/heimdall
# or 
yarn add -D @fimbul/wotan @fimbul/heimdall

Using TSLint Formatters

wotan -m @fimbul/heimdall -f code-frame

-f code-frame refers to the TSLint core CodeFrameFormatter.

The -m @fimbul/heimdall argument enables a hook that loads TSLint formatters if no Wotan formatter is found. That means you cannot use a TSLint formatter when a builtin Wotan formatter with the same name exists. Note that findings with severity suggestion are reported as warning through TSLint formatters.

Using TSLint Rules

To enable Heimdall, add the -m @fimbul/heimdall argument when running wotan from CLI.

wotan -m @fimbul/heimdall

Specifying TSLint rules in your .wotanrc.yaml works as follows. Note that you need to specify a prefix for TSLint rules (tslint/ in this example)

---
rulesDirectories:
  tslint: # enables TSLint core rules 
  tcc: ./node_modules/tslint-consistent-codestyle/rules # enables custom TSLint rules provided by the package 'tslint-consistent-codestyle'. the path may be different for each package 
rules:
  no-unused-expression: error # without prefix this is a Wotan core rule 
  tslint/no-unused-expression: error # with prefix this refers to the TSLint core rule 
  tslint/semicolon: # TSLint core rule 'semicolon' with option 'always' 
    options: always
  tcc/no-unused: error # 'no-unused' from tslint-consistent-codestyle 

Since all paths in rulesDirectories are treated as relative paths (i.e. not resolved using node module resolution), you need to provide the relative paths for node modules as shown above. As an alternative you can resolve the module using require.resolve. For this to work, you need to rename .wotanrc.yaml to .wotanrc.js and change the content as follows:

const path = require('path');
module.exports = {
  rulesDirectories: {
    tslint: '.' // enables TSLint core rules
    tcc: path.dirname(require.resolve('tslint-consistent-codestyle')) // enables custom TSLint rules provided by the package 'tslint-consistent-codestyle'. the path may be different for each package
  }
  rules: {
    'no-unused-expression': 'error' // without prefix this is a Wotan core rule
    'tslint/no-unused-expression': 'error' // with prefix this refers to the TSLint core rule
    'tslint/semicolon': { // TSLint core rule 'semicolon' with option 'always'
      options: 'always'
    }
    'tcc/no-unused': 'error' // 'no-unused' from tslint-consistent-codestyle
  }
}

Enable this Plugin Module in Configuration

If you want to always use this plugin module and don't want to add -m @fimbul/heimdall to the CLI every time, you can add it to your .fimbullinter.yaml file which contains default values for CLI arguments.

Use wotan save -m @fimbul/heimdall to create of update .fimbullinter.yaml. From now on Heimdall will always be loaded unless you override it with another -m argument.

Why!?

Why should you use Wotan to execute TSLint rules?

  • Allows you to reuse existing rules and rules packages without any modification.
  • Enables the use of processors, to lint for example Vue Single File Components (see @fimbul/ve), that are currently not supported by TSLint.
  • Configuration goodness provided by Wotan:
    • Overrides to change the config by matching glob patterns.
    • You can use a rule with the same name from different packages. Because you need to specify a prefix for every package, rules won't get overidden by other packages.
    • Aliases
    • JSON5 support
  • Blazingly fast autofixing, especially when linting the whole project with the -p flag.
  • Smart handling of overlapping fixes avoids destroying your code.

License

Apache-2.0 © Klaus Meinhardt

Install

npm i @fimbul/heimdall

DownloadsWeekly Downloads

334

Version

0.21.0

License

Apache-2.0

Unpacked Size

21.4 kB

Total Files

7

Last publish

Collaborators

  • avatar
  • avatar