-
-
Notifications
You must be signed in to change notification settings - Fork 43
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix(ESLint): Missing multi-configuration handling in monorepo
- Loading branch information
Showing
12 changed files
with
71 additions
and
104 deletions.
There are no files selected for viewing
35 changes: 29 additions & 6 deletions
35
packages/eslint-plugin/src/functions/filter-collision-classes.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,30 @@ | ||
import { createSyncFn } from 'synckit' | ||
import runFilterCollisionClasses from './filter-collision-classes.worker' | ||
import { join } from 'path' | ||
import { generateValidRules } from '@master/css-validator' | ||
import { MasterCSS, Rule, areRuleStatesEqual, areRulesDuplicated } from '@master/css' | ||
|
||
export default process.env.NODE_ENV === 'test' | ||
? runFilterCollisionClasses | ||
: createSyncFn(join(__dirname, 'filter-collision-classes.worker.cjs')) as typeof runFilterCollisionClasses | ||
export default function filterCollisionClasses(classNames: string[], css: MasterCSS): Record<string, string[]> { | ||
const validRules = classNames | ||
.map(eachClassName => generateValidRules(eachClassName, css)[0]) | ||
.filter(Boolean) as Rule[] | ||
const collisionClassesRecord: Record<string, string[]> = {} | ||
for (let i = 0; i < classNames.length; i++) { | ||
const className = classNames[i] | ||
const rule = validRules.find((eachValidRule) => eachValidRule.className === className) | ||
const collisionClasses = [] | ||
if (rule) { | ||
for (let j = 0; j < classNames.length; j++) { | ||
const compareClassName = classNames[j] | ||
const compareRule = validRules.find((eachValidRule) => eachValidRule.className === compareClassName) | ||
if (i !== j && compareRule | ||
&& areRulesDuplicated(rule, compareRule) | ||
&& areRuleStatesEqual(rule, compareRule) | ||
) { | ||
collisionClasses.push(compareClassName) | ||
} | ||
} | ||
if (collisionClasses.length > 0) { | ||
collisionClassesRecord[className] = collisionClasses | ||
} | ||
} | ||
} | ||
return collisionClassesRecord | ||
} |
35 changes: 0 additions & 35 deletions
35
packages/eslint-plugin/src/functions/filter-collision-classes.worker.ts
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
7 changes: 0 additions & 7 deletions
7
packages/eslint-plugin/src/functions/reorder-valid-classes.ts
This file was deleted.
Oops, something went wrong.
11 changes: 0 additions & 11 deletions
11
packages/eslint-plugin/src/functions/reorder-valid-classes.worker.ts
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,10 +1,35 @@ | ||
import type { RuleContext } from '@typescript-eslint/utils/ts-eslint' | ||
import settings from '../settings' | ||
import settings, { Settings } from '../settings' | ||
import exploreConfig from '@master/css-explore-config' | ||
import { Config, MasterCSS } from '@master/css' | ||
|
||
declare type CSSCache = { | ||
cwd: string | ||
settings: Settings, | ||
css: MasterCSS, | ||
} | ||
|
||
const cssCaches: CSSCache[] = [] | ||
|
||
export default function resolveContext(context: RuleContext<any, any[]>) { | ||
const resolvedSettings = Object.assign(settings, context.settings?.['@master/css']) | ||
const resolvedSettings = Object.assign({}, settings, context.settings?.['@master/css']) | ||
let css = cssCaches.find(cache => cache.settings.config === resolvedSettings.config && | ||
cache.cwd === context.cwd)?.css | ||
|
||
if (!css) { | ||
let config: Config | ||
if (typeof resolvedSettings.config === 'object') { | ||
config = resolvedSettings.config | ||
} else { | ||
config = exploreConfig({ name: resolvedSettings.config, found: undefined }) | ||
} | ||
css = new MasterCSS(config) | ||
cssCaches.push({ cwd: context.cwd, settings: resolvedSettings, css }) | ||
} | ||
|
||
return { | ||
settings: resolvedSettings, | ||
options: context.options[0] || {} | ||
options: context.options[0] || {}, | ||
css | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters