eslint-plugin-tailwindcss
Advanced tools
Comparing version 3.17.1 to 3.17.2
@@ -6,5 +6,5 @@ 'use strict'; | ||
const postcss = require('postcss'); | ||
const removeDuplicatesFromArray = require('./removeDuplicatesFromArray'); | ||
const classRegexp = /\.([^\.\,\s\n\:\(\)\[\]\'~\+\>\*\\]*)/gim; | ||
let previousGlobsResults = []; | ||
let lastUpdate = null; | ||
@@ -14,7 +14,2 @@ let classnamesFromFiles = []; | ||
/** | ||
* @type {Map<string, number} | ||
*/ | ||
const prevEditedTimestamp = new Map() | ||
/** | ||
* Read CSS files and extract classnames | ||
@@ -27,54 +22,25 @@ * @param {Array} patterns Glob patterns to locate files | ||
const now = new Date().getTime(); | ||
const files = fg.sync(patterns, { suppressErrors: true }); | ||
const newGlobs = previousGlobsResults.flat().join(',') != files.flat().join(','); | ||
const expired = lastUpdate === null || now - lastUpdate > refreshRate; | ||
if (!expired) { | ||
return classnamesFromFiles; | ||
} | ||
const files = fg.sync(patterns, { suppressErrors: true, stats: true }); | ||
lastUpdate = now; | ||
/** | ||
* @type {Set<string} | ||
*/ | ||
const detectedClassnames = new Set(); | ||
/** | ||
* @type {Set<string>} | ||
*/ | ||
const filesSet = new Set(); | ||
for (const { path: file, stats } of files) { | ||
filesSet.add(file); | ||
if (!stats) {} | ||
// file is not changed -> we do need to do extra work | ||
else if (prevEditedTimestamp.get(file) === stats.mtimeMs) { | ||
continue; | ||
} else { | ||
prevEditedTimestamp.set(file, stats.mtimeMs); | ||
if (newGlobs || expired) { | ||
previousGlobsResults = files; | ||
lastUpdate = now; | ||
let detectedClassnames = []; | ||
for (const file of files) { | ||
const data = fs.readFileSync(file, 'utf-8'); | ||
const root = postcss.parse(data); | ||
root.walkRules((rule) => { | ||
const regexp = /\.([^\.\,\s\n\:\(\)\[\]\'~\+\>\*\\]*)/gim; | ||
const matches = [...rule.selector.matchAll(regexp)]; | ||
const classnames = matches.map((arr) => arr[1]); | ||
detectedClassnames.push(...classnames); | ||
}); | ||
detectedClassnames = removeDuplicatesFromArray(detectedClassnames); | ||
} | ||
const data = fs.readFileSync(file, 'utf-8'); | ||
const root = postcss.parse(data); | ||
root.walkRules((rule) => { | ||
for (const match of rule.selector.matchAll(classRegexp)) { | ||
detectedClassnames.add(match[1]); | ||
} | ||
}); | ||
classnamesFromFiles = detectedClassnames; | ||
} | ||
// avoiding memory leak | ||
{ | ||
/** | ||
* @type {string[]} | ||
*/ | ||
const keysToDelete = [] | ||
for (const cachedFilePath of prevEditedTimestamp.keys()) { | ||
if (!filesSet.has(cachedFilePath)) { | ||
keysToDelete.push(cachedFilePath); | ||
} | ||
} | ||
for (const key of keysToDelete) { | ||
prevEditedTimestamp.delete(key); | ||
} | ||
} | ||
classnamesFromFiles = [...detectedClassnames]; | ||
return classnamesFromFiles | ||
return classnamesFromFiles; | ||
}; | ||
module.exports = generateClassnamesListSync; |
{ | ||
"name": "eslint-plugin-tailwindcss", | ||
"version": "3.17.1", | ||
"version": "3.17.2", | ||
"description": "Rules enforcing best practices while using Tailwind CSS", | ||
@@ -5,0 +5,0 @@ "keywords": [ |
@@ -44,3 +44,2 @@ # eslint-plugin-tailwindcss | ||
- perf: [`no-custom-classname` optimization](https://github.com/francoismassart/eslint-plugin-tailwindcss/pull/338) (by [XantreDev](https://github.com/XantreDev) π) | ||
- fix: [support `tag.div` and `tag(Component)`](https://github.com/francoismassart/eslint-plugin-tailwindcss/pull/302) (by [nihalgonsalves](https://github.com/nihalgonsalves) π) | ||
@@ -47,0 +46,0 @@ - feat: [**support flat config and ESLint 9**](https://github.com/francoismassart/eslint-plugin-tailwindcss/pull/330) (by [kazupon](https://github.com/kazupon) π) |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
215101
5478
300