bmatcuk / eslint-plugin-postcss-modules

Checks that you are using the classes exported by your css modules using postcss.
MIT License
21 stars 7 forks source link

Don't cache `specifierToClasses` entries across multiple files #1

Closed charlessuh closed 4 years ago

charlessuh commented 4 years ago

Hi.

specifierToClasses being static / global is okay in many cases, because these lines overwrite the cache entry (if one existed from a previous file) for a specifier name (like Styles in import Styles from 'file.css') when processing an import declaration: https://github.com/bmatcuk/eslint-plugin-postcss-modules/blob/5e8353c25368eabcb1bcd0e4748683a7c83fb6d5/lib/rules/common/cache.ts#L161-L166

However, there are cases where these lines don't run -- for example, if processing the import declaration returned early: https://github.com/bmatcuk/eslint-plugin-postcss-modules/blob/5e8353c25368eabcb1bcd0e4748683a7c83fb6d5/lib/rules/common/cache.ts#L131-L139

For example: let's say fileA.jsx contains import Styles from './fileA.css' and fileB.jsx contains import Styles from './fileB.scss' (so processing the import declaration in fileB.jsx returns early.)

If fileB.jsx is linted after fileA.jsx, the cached entry from the previous file may be used.

codecov[bot] commented 4 years ago

Codecov Report

Merging #1 into master will not change coverage. The diff coverage is 100%.

Impacted file tree graph

@@          Coverage Diff           @@
##           master      #1   +/-   ##
======================================
  Coverage    97.1%   97.1%           
======================================
  Files          11      11           
  Lines         207     207           
  Branches       33      33           
======================================
  Hits          201     201           
  Misses          2       2           
  Partials        4       4
Impacted Files Coverage Δ
lib/rules/common/cache.ts 96.29% <100%> (ø) :arrow_up:

Continue to review full report at Codecov.

Legend - Click here to learn more Δ = absolute <relative> (impact), ø = not affected, ? = missing data Powered by Codecov. Last update 07b2e54...4a241ca. Read the comment docs.