Skip to content

v0.4.0 – Allow Rule Overrides

Compare
Choose a tag to compare
@saadq saadq released this 22 Jun 01:09

v0.4.0

This release will allow you to override lynt's default rule configuration. Note that any rules defined as "style rules" in ESLint or TSLint are still not allowed to be used. This is to encourage users to rely on better tools when it comes to code formatting, such as Prettier.

Configuring Lynt

There has always been 3 ways to configure lynt

– Command Line arguments
– Setting a lynt property in package.json
– Creating a .lyntrc file in your root project folder

To customize rules, you must use one of the last 2, you cannot do so with command line arguments. You can still use the CLI for all the other configuration options if you want though.

In the examples below, I'll be using an example .lyntrc file, but everything could also be done with the package.json style as well.

The examples work for both ESLint and TSLint configuration (though obviously if TSLint is being used, you can't add ESLint rules to it or vice-versa).

Disabling default rules

You can disable rules by passing the rule name and setting its value to off or false.

.lyntrc

{
  "rules": {
    "curly": "off"
  }
}

This will remove the curly rule from lynt's default ESLint config.

Enabling extra rules

You can enable rules by passing the rule name and setting its value to on or true to use the default setting for a rule. If you want to pass something more complex, you can do that as well.

.lyntrc

{
  "rules": {
    "prefer-const": "on",
    "no-console": "on",
    "no-unused-expressions": [
      "error",
        {
          "allowShortCircuit": true
        }
    ]
  }
}

Configuration File Example

Thought it might be helpful to see a larger config file just as a reference. This config adds support for TypeScript, React, and --fix by default, as well as including some rule configuration.

.lyntrc

{
  "typescript": true,
  "react": true,
  "fix": true,
  "rules": {
    "prefer-const": "on",
    "no-unused-expression": "off"
  }
}

I'll be updating the readme soon to include this info about configuration.