Tslint: No valid rules have been specified

Created on 26 Feb 2018  ·  14Comments  ·  Source: palantir/tslint

Bug Report

  • __TSLint version__: 5.9.1
  • __TypeScript version__: 2.7.2
  • __Running TSLint via__: VScode on Mac, but fails on CLI too

With tslint.json configuration:

{
    "defaultSeverity": "none",
    "extends": [
        "tslint:recommended"
    ],
    "jsRules": {},
    "rules": {
        "no-internal-module": false,
        "typedef-whitespace": false,
        "variable-name": [
            true,
            "check-format",
            "allow-leading-underscore"
        ],
        "no-console": false,
        "no-reference": false,
        "no-namespace": false,
        "max-line-length": [true, 140],
        "no-bitwise": false,
        "align": true,
        "arrow-return-shorthand": true,
        "no-magic-numbers": true
    },
    "rulesDirectory": []
}

Actual behavior

Last week my tslint was working fine with the above configuration. Today I updated my VSCode, and TSLint started complaining that no compatible version of Typescript was installed. To fix this I did npm install -g typescript which fixed the TSLint version error.

The TSLint extension in VSCode gives the warning No valid rules have been specified, and doesn't lint anything.

I tried running tslint --project build from the CLI, but I get the same error.

I thought maybe tslint was looking for a global configuration file, but if I add a syntax error to my local tslint.json, I'll get a different error Unexpected token f, so it seems it is looking at the local config but then failing somehow

Expected behavior

TSLint should run over the project as it did before

Most helpful comment

I've found a possible solution:
If you're using setting "allowJs": true in tsconfig.json, it will try to find rules and jsRules from tslint.json.

If your jsRules is empty, it will complain. IMO the messages should indicate which rules it is actually parsing.

Adding a rule inside jsRules made the message go away.

"jsRules": {
    "no-empty": true
}

All 14 comments

I have the same issue ~coming from 5.8.0 to 5.9.1~.

Running tslint --config tslint.json --project tsconfig.json spits the same No valid rules have been specified error.

tslint.json:

{
    "extends": ["tslint-config-prettier", "tslint-react"],
    "rules": {
        "ban": false,
        "class-name": true,
        "comment-format": [
            true,
            "check-space"
        ],
        "curly": true,
        "eofline": false,
        "forin": true,
        "interface-name": [true, "never-prefix"],
        "jsdoc-format": true,
        "jsx-no-lambda": false,
        "jsx-no-multiline-js": false,
        "label-position": true,
        "no-any": false,
        "no-arg": true,
        "no-bitwise": true,
        "no-console": [
            false,
            "log",
            "error",
            "debug",
            "info",
            "time",
            "timeEnd",
            "trace"
        ],
        "no-construct": true,
        "no-debugger": true,
        "no-duplicate-variable": true,
        "no-empty": true,
        "no-eval": true,
        "no-shadowed-variable": true,
        "no-string-literal": true,
        "no-switch-case-fall-through": true,
        "no-trailing-whitespace": false,
        "no-unused-variable": true,
        "no-unused-expression": true,
        "no-use-before-declare": true,
        "radix": true,
        "switch-default": true,

        "trailing-comma": [false],

        "triple-equals": [ true, "allow-null-check" ],
        "typedef": [
            true,
            "parameter",
            "property-declaration"
        ],
        "variable-name": [true, "ban-keywords", "check-format", "allow-leading-underscore", "allow-pascal-case"]
    }
}

I've found a possible solution:
If you're using setting "allowJs": true in tsconfig.json, it will try to find rules and jsRules from tslint.json.

If your jsRules is empty, it will complain. IMO the messages should indicate which rules it is actually parsing.

Adding a rule inside jsRules made the message go away.

"jsRules": {
    "no-empty": true
}

I just tried adding:

"allowJs": true,
"jsRules": {
    "no-empty": true
}

To my tslint.json, but unfortunately the message stays, and it doesn't seem to lint anything still

What do you get on your output? If there’s no errors then it should be working fine.

I get the same output/warning, changing it didn't do anything 😢

@nattyxd did you add jsRules to your tsconfig or tslint.json? allowJs is in tsconfig; with allowJs your tslint.json is expecting some jsRules (hence the bug). A workaround would be to add "jsRules": { "no-empty": true } to your tslint.json so that it has a rule and doesn't complain. This shouldn't have any impact I think. It's just a small annoyance.

@ajcrites Absolutely on point. I think this issue should be closed.

Closing this issue as it seems to be resolved.

Several months ago I had this issue, then it was solved by the solution explained in this thread, and it was all okey for a while, but recently I started having this issue again, though I do have "no-empty": true. Banging my head and cannot figure out what could be the problem.

I removed everything from tslint.json and added the following and seems to be working

{
"extends": "@microsoft/sp-tslint-rules/base-tslint.json",
"rules": {
"class-name": false,
"export-name": false,
"forin": false,
"label-position": false,
"member-access": true,
"no-arg": false,
"no-console": false,
"no-construct": false,
"no-duplicate-variable": true,
"no-eval": false,
"no-function-expression": true,
"no-internal-module": true,
"no-shadowed-variable": true,
"no-switch-case-fall-through": true,
"no-unnecessary-semicolons": true,
"no-unused-expression": true,
"no-use-before-declare": true,
"no-with-statement": true,
"semicolon": true,
"trailing-comma": false,
"typedef": false,
"typedef-whitespace": false,
"use-named-parameter": true,
"variable-name": false,
"whitespace": false
}
}

If you don't want TSLint linting JS files (and you have tslint >= 5.8), simply add the following to your tslint.json:

"linterOptions": {
    "exclude": [
        "**/*.js"
    ]
}

Add tslint --config tslint.js works for me.

you need to specify the config file, like tslint -c .eslintrc.yml -p tsconfig.json, and there is nothing that's required from above like jsRules or all of those..

🤖 Beep boop! 👉 TSLint is deprecated 👈 and you should switch to typescript-eslint! 🤖

🔒 This issue is being locked to prevent further unnecessary discussions. Thank you! 👋

Was this page helpful?
0 / 5 - 0 ratings

Related issues

DanielKucal picture DanielKucal  ·  3Comments

zewa666 picture zewa666  ·  3Comments

sumitkmr picture sumitkmr  ·  3Comments

CSchulz picture CSchulz  ·  3Comments

denkomanceski picture denkomanceski  ·  3Comments