alexilyaev / stylelint-find-rules

Find stylelint rules that are not configured in your stylelint config.
MIT License
27 stars 4 forks source link

Error: Unhandled promise rejection #8

Closed ntwb closed 7 years ago

ntwb commented 7 years ago

Testing with https://github.com/WordPress-Coding-Standards/stylelint-config-wordpress

Results in error: (node:82670) UnhandledPromiseRejectionWarning: Unhandled promise rejection (rejection id: 1): TypeError: Cannot read property 'config' of null

Tested using Node.js v6.11.1 and v8.2.1

Via cli:

~/dev/stylelint/stylelint-config-wordpress stylelint-find-rules* 
❯ ./node_modules/.bin/stylelint-find-rules 
(node:82670) UnhandledPromiseRejectionWarning: Unhandled promise rejection (rejection id: 1): TypeError: Cannot read property 'config' of null

Via package.json npm script:

~/dev/stylelint/stylelint-config-wordpress stylelint-find-rules* 
❯ npm run stylelint-find-unused-rules

> stylelint-config-wordpress@12.0.0 stylelint-find-unused-rules /Users/netweb/dev/stylelint/stylelint-config-wordpress
> stylelint-find-rules

(node:82697) UnhandledPromiseRejectionWarning: Unhandled promise rejection (rejection id: 1): TypeError: Cannot read property 'config' of null

How I tested it:

diff --git package.json package.json
index 005f044..fd41454 100644
--- package.json
+++ package.json
@@ -47,7 +47,8 @@
     "remark-preset-lint-consistent": "^2.0.0",
     "remark-preset-lint-recommended": "^3.0.0",
     "strip-ansi": "^4.0.0",
-    "stylelint": "^8.0.0"
+    "stylelint": "^8.0.0",
+    "stylelint-find-rules": "^0.6.0"
   },
   "peerDependencies": {
     "stylelint": "^7.10.1"
@@ -60,6 +61,7 @@
     "lint": "npm-run-all --parallel lint:*",
     "pretest": "npm run lint",
     "release": "npmpub --verbose",
+    "stylelint-find-unused-rules": "stylelint-find-rules",
     "test": "jest",
     "watch": "jest --watch"
   },
alexilyaev commented 7 years ago

Hi, thanks for the detailed report.

So, it seems like it doesn't find any config for Stylelint, based on:
https://github.com/davidtheclark/cosmiconfig

I suppose we should fail properly and note that it didn't find any config.
At least that's what I'd expect if I'd use this tool without a config.

What do you think?

ntwb commented 7 years ago

I expected it to work "as is", if you try and use it as noted in #7 you would get the same results

alexilyaev commented 7 years ago

I mean, would you expect it to fail and tell you it didn't find a config?
Or perhaps something else?

The purpose of this tool is to find available stylelint rules that are not configured in your config.

ntwb commented 7 years ago

Right, the reason is that all 3 of these repos are shared configs rather than configurations that stylelint would normally detect using cosmiconfig

So it would be great if stylelint-find-rules could add support for shared configs so that it can be used as a tool to detect any rules missing from a shared config and not just cosmiconfig detected configurations such as .stylelintrc etc 😄

alexilyaev commented 7 years ago

@ntwb Is this for making the development of shared configs easier?

I could add a --config flag and you'd pass the path to index.js in your case.
Is that viable?

alexilyaev commented 7 years ago

@ntwb Turns out we already had support for --config through cosmiconfig :-)

I've made some changes any way to print an error if a config is not found and documented the custom config case with --config:
https://github.com/alexilyaev/stylelint-find-rules#custom-config-file

Release notes: https://github.com/alexilyaev/stylelint-find-rules/releases/tag/v0.7.0

ntwb commented 7 years ago

Works great @alexilyaev 👌

ntwb commented 7 years ago

Done 💥 https://github.com/WordPress-Coding-Standards/stylelint-config-wordpress/pull/167

alexilyaev commented 7 years ago

Just realized if the config itself extends something, I'm not following it, hmm.
Opening a new issue :-).