progre/tslint-config-airbnb

"No valid rules have been specified" When Using tslint-config-airbnb

Closed this issue · 9 comments

When I use tslint --init I get the following config:

{
  "defaultSeverity": "error",
  "extends": [
      "tslint:recommended"
  ],
  "jsRules": {},
  "rules": {},
  "rulesDirectory": []
}

If I use that config and run TSLint against my code I see errors, as expected. However, when I change just one line (after installing tslint-config-airbnb) :

  "extends": [
      "tslint-config-airbnb"
  ],

I get the following output when I run TSLint:

No valid rules have been specified

which suggests that the airbnb rules are not loading. Furthermore, even if I add a valid rule:

"rules": {
  "quotemark": [true, "single"]
},

I still get the same message, suggesting that it has short-circuited the whole rules-loading process.

Is there any obvious cause for this, and if not is there any way I can trigger some sort of debugging or logging to determine what's going wrong?

I tryed it on clean project, but it was success.
Could you try again on clean (no other dependencies) project?

Thanks for the suggestion. I'm sure it works in a clean project, I just had hoped I might be able to get some further information on how to fix it in my project (either from you if you'd run in to it before, or from any sort of --debug type flag I could use).

But it sounds like not, so I'll just have to play the "copy line by line from the non-working project to the working project until something breaks" game. But thanks anyway for your time.

@machineghost any luck working out which line caused this? I just switched from gulp-tslint to using tslint directly, it works in VSCode and it actually lints correctly according to my rules but it still says that as the first line of output in each run.

actually for me it was that I didn't have any jsRules defined. I didn't actually want any but I put a dummy one in just to suppress the warning.

Thankfully I no longer have to use Typescript/TSLint, so I never did figure out the source. Glad you were able to solve it though.

I think the issue is when running it in webpack with a lint loader, e.g. tslint-loader because it works fine from the command line.

No valid rules have been specified
Hash: 336df40a95e93bf8a6a0
Version: webpack 3.8.1
Time: 1823ms
                                                                Asset       Size  Chunks             Chunk Names
                                                             index.js     211 kB       0  [emitted]  index
                                                       src/index.d.ts   85 bytes          [emitted]
                    src/components/DummyComponent/DummyComponent.d.ts  112 bytes          [emitted]
                             src/components/DummyComponent/index.d.ts   78 bytes          [emitted]
src/components/DummyComponent/__stories__/DummyComponent-stories.d.ts    0 bytes          [emitted]
     src/components/DummyComponent/__tests__/DummyComponent-test.d.ts    0 bytes          [emitted]
   [6] multi ./src/index 28 bytes {0} [built]
   [7] ./src/index.ts 191 bytes {0} [built]
    + 13 hidden modules
> tslint -p ./                                                                                                                2s 914ms

ERROR: /Users/nickytonline/dev/some-project/src/components/DummyComponent/DummyComponent.tsx[3, 7]: variable name must be in lowerCamelCase or UPPER_CASE

If I just declare a rule(s) with no extends it works, e.g.

{
   "rules": {
      "variable-name": true
   }
}

> rimraf ./dist && NODE_ENV=production webpack


Hash: 9af18522dcbb68880f7d
Version: webpack 3.8.1
Time: 1223ms
Asset Size Chunks Chunk Names
index.js 7.61 kB 0 [emitted] index
src/index.d.ts 85 bytes [emitted]
src/components/DummyComponent/DummyComponent.d.ts 112 bytes [emitted]
src/components/DummyComponent/index.d.ts 78 bytes [emitted]
src/components/DummyComponent/__stories__/DummyComponent-stories.d.ts 0 bytes [emitted]
src/components/DummyComponent/__tests__/DummyComponent-test.d.ts 0 bytes [emitted]
[0] multi ./src/index 28 bytes {0} [built]
[1] ./src/index.ts 191 bytes {0} [built]
+ 2 hidden modules


WARNING in ./src/components/DummyComponent/DummyComponent.tsx
[3, 7]: variable name must be in lowerCamelCase or UPPER_CASE


@ ./src/components/DummyComponent/index.ts 3:23-50
@ ./src/index.ts
@ multi ./src/index


ERROR in ./src/components/DummyComponent/DummyComponent.tsx
Module build failed: Error: Compilation failed due to tslint errors.
at report (/Users/nickytonline/dev/some-project/node_modules/tslint-loader/index.js:93:11)
at lint (/Users/nickytonline/dev/some-project/node_modules/tslint-loader/index.js:74:3)
at Object.module.exports (/Users/nickytonline/dev/some-project/node_modules/tslint-loader/index.js:140:3)
@ ./src/components/DummyComponent/index.ts 3:23-50
@ ./src/index.ts
@ multi ./src/index
npm ERR! code ELIFECYCLE
...

This is not specific to tslint-config-airbnb though. It happens as soon as you extend your tslint config with any extension of rules.

@nickytonline I believe this can be fixed by doing something along these lines:

{
  "extends": ["tslint:latest", "tslint-config-airbnb"],
  "rules": {
    "trailing-comma": [true],
    "no-string-throw": false
  }
}

I had the same problem and I found that it's related to the "allowJs": true config in my tsconfig.json. When tslint runs on a .js file, the jsRules Map is empty, and then it logs that warning. i think @jamonholmgren found more success adding the other config in "extends" because that config happens to specify jsRules.

Feature request: i think the fix here is to actually copy the relevant (not TS-only) rules into a jsRules property to export.