keplersj / jest-runner-stylelint

Stylelint runner for Jest
https://keplersj.com/projects/jest-runner-stylelint/
20 stars 10 forks source link

Acknowledge Ignored Files by Skipping #3

Open whilelucky opened 6 years ago

whilelucky commented 6 years ago

Hey @keplersj, first off, thanks for creating this project :)

Wanted to see if there's gonna be any feature to respect .stylelintignore rules automatically like jest-runner-eslint?

Right now it seems to be matching all *.css files(based on testMatch) regardless of what is mentioned in the .stylelintignore config.

keplersj commented 6 years ago

Hey @lakshyaranganath, thanks for checking it out! 😀

Hmm... Have you tried it to see if it doesn't work? Under the hood of this runner, stylelint should support that by default out of the box.

If it doesn't work let me know and I should be able to do something about that.

whilelucky commented 6 years ago

Hey @keplersj, yeah I'm reporting this only after trying it for myself. So I'm using the following setup to lint my .js files. (since I used styled-components, I have my styles in my .js files)

jest config

displayName: 'stylelint',
runner: 'jest-runner-stylelint',
testMatch: ['**/*.js'],

.stylelintignore

.idea
.vscode
es
lib
docs
coverage
node_modules
npm-debug.log*

Output from jest

 RUNS   stylelint  lib/components/Tabs/index.js
 RUNS   stylelint  lib/theme/theme.js
 RUNS   stylelint  es/components/Chip/index.js
 RUNS   stylelint  lib/components/TextInput/TextInput.js
 RUNS   stylelint  es/components/Notification/Notification.js
 RUNS   stylelint  lib/components/Card/index.js
 RUNS   stylelint  es/components/Card/Card.js
 RUNS   stylelint  lib/components/Aux/Aux.js
 RUNS   stylelint  lib/components/Divider/Divider.js
 RUNS   stylelint  lib/index.js
 RUNS   stylelint  lib/components/Divider/index.js
 RUNS   stylelint  lib/components/Dropdown/Dropdown.js
 RUNS   stylelint  es/components/Flex/index.js
 RUNS   stylelint  lib/components/List/ListItem.js
 RUNS   stylelint  es/components/Modal/ModalHeader.js
 RUNS   stylelint  es/components/Modal/index.js
 RUNS   stylelint  lib/components/List/List.js
 RUNS   stylelint  es/index.js
 RUNS   stylelint  es/components/Modal/ModalContent.js
 RUNS   stylelint  lib/components/Dropdown/index.js

as you can see it tries to lint files in the es/ and lib/ directories although its ignored in the .stylelintignore file.

Let me know if you need any other info regarding this. Will be super glad to help :)

keplersj commented 6 years ago

Ah. I think I know what's happening. Under the hood of this runner stylelint is ignoring the files in es/*, however Jest isn't. Jest reports the files in es/* as running because from Jest's perspective they are being run. And because those files are being ignored by stylelint they are not reporting errors, and Jest is told that the file is successful.

I'm not sure what the behavior should be with this scenario to be honest. It looks like stylelint does include if a linted file is ignored so I can handle this case pretty easily, just not sure what would work best. I believe there are two options - either not report anything for ignored files (which should prevent them from showing up as running and successful) or do the more verbose and explicit behavior and mark the file as skipped, equivalent to describe.skip.

Let me know what your preferred solution is, I'm leaning a bit more toward the skipping functionality but I also tend to lean more toward explicit solutions.

whilelucky commented 6 years ago

Sweet, thanks for catching that so quickly.

Marking the files skipped seems to be the preferred way runners are written. Even the jest-runner-eslint package marks all .eslintignore files skipped to keep the explicitness and verbosity :)