Skip to content

Commit 5b12206

Browse files
committed
Update ESLint config
1 parent df63790 commit 5b12206

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

85 files changed

+9055
-10170
lines changed

.eslintrc.yml

-3
This file was deleted.

.vscode/settings.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
{
2+
"eslint.useFlatConfig": true,
23
"yaml.format.singleQuote": true,
34
"javascript.format.semicolons": "remove",
45
"[yaml]": {
56
"editor.insertSpaces": true,
67
"editor.tabSize": 4
78
},
8-
"eslint.useFlatConfig": false,
99
"eslint.validate": [
1010
"html",
1111
"php",

benchmarks/package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
"extract": "hyperfine 'cd extract/tailwindcss && npx tailwindcss -i src/main.css' 'cd extract/mastercss && npx mastercss extract --no-export'"
55
},
66
"dependencies": {
7-
"@techor/log": "^3.0.11",
7+
"@techor/log": "^3.1.4",
88
"axios": "^1.6.7",
99
"cheerio": "0.22.0",
1010
"filesize": "^10.1.0",

eslint.config.mjs

+7
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
import techor from 'eslint-config-techor'
2+
import tseslint from 'typescript-eslint'
3+
4+
export default tseslint.config(
5+
techor.configs.base,
6+
techor.configs.stylistic
7+
)

package.json

+14-13
Original file line numberDiff line numberDiff line change
@@ -21,32 +21,32 @@
2121
"url": "https://github.com/master-co/css.git"
2222
},
2323
"dependencies": {
24-
"@swc-node/jest": "^1.8.0",
25-
"@techor/fs": "^3.0.22",
26-
"@techor/glob": "^3.0.22",
27-
"@techor/jest-dom": "^3.0.22",
28-
"@techor/repo": "^3.0.22",
29-
"@types/node-fetch": "^2.6.11",
24+
"@swc-node/jest": "^1.8.12",
25+
"@techor/fs": "^3.1.4",
26+
"@techor/glob": "^3.1.4",
27+
"@techor/jest-dom": "^3.1.4",
28+
"@techor/repo": "^3.1.4",
29+
"@types/node-fetch": "^2.6.12",
3030
"@types/shuffle-array": "^1.0.5",
3131
"cross-env": "^7.0.3",
32+
"eslint": "^9.15.0",
3233
"fast-glob": "^3.3.2",
33-
"get-tsconfig": "^4.7.3",
34+
"get-tsconfig": "^4.8.1",
3435
"jest-extended": "^4.0.2",
3536
"jest-text-transformer": "^1.0.4",
3637
"nanoid": "^4.0.2",
3738
"shuffle-array": "^1.0.1",
3839
"spawnd": "^9.0.2",
3940
"strip-ansi": "^7.1.0",
40-
"techor": "^3.0.22",
41-
"tinybench": "^2.6.0",
41+
"techor": "^3.1.4",
42+
"tinybench": "^2.9.0",
4243
"ts-dedent": "^2.2.0",
43-
"ts-jest": "^29.1.2",
44-
"tsx": "^4.7.1",
44+
"ts-jest": "^29.2.5",
45+
"tsx": "^4.19.2",
4546
"vite-tsconfig-paths": "^4.3.2",
4647
"vitest": "^1.6.0"
4748
},
4849
"devDependencies": {
49-
"shared": "workspace:^",
5050
"@master/create-css": "workspace:^",
5151
"@master/css": "workspace:^",
5252
"@master/css-cli": "workspace:^",
@@ -65,6 +65,7 @@
6565
"@master/css.vue": "workspace:^",
6666
"@master/eslint-config-css": "workspace:^",
6767
"@master/eslint-plugin-css": "workspace:^",
68-
"master-css-vscode": "workspace:^"
68+
"master-css-vscode": "workspace:^",
69+
"shared": "workspace:^"
6970
}
7071
}

packages/cli/.eslintrc.yml

-2
This file was deleted.

packages/cli/eslint.config.mjs

+7
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
import common from '../../eslint.config.mjs'
2+
import techor from 'eslint-config-techor'
3+
4+
export default [
5+
...common,
6+
techor.configs.typescript,
7+
]

packages/cli/package.json

+5-5
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
"scripts": {
44
"build": "techor build \"src/**/*.ts\" --formats esm",
55
"dev": "pnpm build --watch",
6-
"lint": "eslint ./src",
6+
"lint": "eslint",
77
"type-check": "tsc --noEmit",
88
"test": "vitest"
99
},
@@ -42,10 +42,10 @@
4242
"@master/css-explore-config": "workspace:^",
4343
"@master/css-extractor": "workspace:^",
4444
"@master/css-server": "workspace:^",
45-
"@techor/extend": "^3.0.22",
46-
"@techor/fs": "^3.0.22",
47-
"@techor/glob": "^3.0.22",
48-
"@techor/log": "^3.0.22",
45+
"@techor/extend": "^3.1.4",
46+
"@techor/fs": "^3.1.4",
47+
"@techor/glob": "^3.1.4",
48+
"@techor/log": "^3.1.4",
4949
"bytes": "^3.1.2",
5050
"chokidar": "^3.6.0",
5151
"commander": "^12.0.0",

packages/core/.eslintrc.yml

-4
This file was deleted.

packages/core/eslint.config.mjs

+12
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
import common from '../../eslint.config.mjs'
2+
import techor from 'eslint-config-techor'
3+
4+
export default [
5+
...common,
6+
techor.configs.typescript,
7+
{
8+
rules: {
9+
'no-undef': 'off',
10+
}
11+
}
12+
]

packages/core/package.json

+2-2
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
"dev": "pnpm build --watch",
77
"test": "vitest",
88
"type-check": "tsc --noEmit",
9-
"lint": "eslint src"
9+
"lint": "eslint"
1010
},
1111
"license": "MIT",
1212
"description": "The CSS language and framework for rapidly building modern and high-performance websites",
@@ -65,7 +65,7 @@
6565
"dependencies": {
6666
"@master/colors": "^2.1.0",
6767
"@master/normal.css": "^3.1.0",
68-
"@techor/extend": "^3.0.23",
68+
"@techor/extend": "^3.1.4",
6969
"csstype": "^3.1.3"
7070
},
7171
"devDependencies": {

packages/core/src/config/index.ts

+11-11
Original file line numberDiff line numberDiff line change
@@ -38,22 +38,22 @@ export {
3838
modes
3939
}
4040

41-
export type VariableValue = number | string | false | Array<number | string>
41+
export type VariableValue = number | string | false | (number | string)[]
4242
export type VariableDefinition = { [key in '' | `@${string}` | string]?: VariableValue | VariableDefinition } | VariableValue
43-
export type CSSKeyframes = { [key in 'from' | 'to' | string]: PropertiesHyphen }
44-
export type AnimationDefinitions = { [key: string]: CSSKeyframes }
45-
export type SelectorDefinitions = { [key: string]: string | string[] }
46-
export type AtDefinitions = { [key: string]: number | string | AtDefinitions }
47-
export type StyleDefinitions = { [key: string]: string | StyleDefinitions }
48-
export type SyntaxDefinitions = { [key in keyof typeof syntaxes | string]?: SyntaxDefinition }
49-
export type VariableDefinitions = { [key in keyof typeof syntaxes]?: VariableDefinition } & { [key: string]: VariableDefinition }
50-
export type UtilityDefinitions = { [key in keyof typeof utilities]?: PropertiesHyphen } & { [key: string]: PropertiesHyphen }
51-
export type ModeDefinitions = { [key: string]: 'class' | 'media' | 'host' | false }
43+
export type CSSKeyframes = Record<'from' | 'to' | string, PropertiesHyphen>
44+
export type AnimationDefinitions = Record<string, CSSKeyframes>;
45+
export type SelectorDefinitions = Record<string, string | string[]>;
46+
export interface AtDefinitions { [key: string]: number | string | AtDefinitions }
47+
export interface StyleDefinitions { [key: string]: string | StyleDefinitions }
48+
export type SyntaxDefinitions = Partial<Record<keyof typeof syntaxes | string, SyntaxDefinition>>
49+
export type VariableDefinitions = { [key in keyof typeof syntaxes]?: VariableDefinition } & Record<string, VariableDefinition>
50+
export type UtilityDefinitions = { [key in keyof typeof utilities]?: PropertiesHyphen } & Record<string, PropertiesHyphen>
51+
export type ModeDefinitions = Record<string, 'class' | 'media' | 'host' | false>;
5252
export interface FunctionDefinition {
5353
unit?: string
5454
transform?(this: Rule, value: string, bypassVariableNames: string[]): string | ValueComponent[]
5555
}
56-
export type FunctionDefinitions = { [key: string]: FunctionDefinition }
56+
export type FunctionDefinitions = Record<string, FunctionDefinition>;
5757

5858
export interface Config {
5959
extends?: (Config | any)[]

packages/core/src/config/styles.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
export type ConfigStyles = { [key: string]: string | ConfigStyles }
1+
export interface ConfigStyles { [key: string]: string | ConfigStyles }

packages/core/src/core.ts

+11-16
Original file line numberDiff line numberDiff line change
@@ -9,16 +9,16 @@ import extendConfig from './utils/extend-config'
99
import { type PropertiesHyphen } from 'csstype'
1010
import './types/global' // fix: ../css/src/core.ts:1205:16 - error TS7017: Element implicitly has an 'any' type because type 'typeof globalThis' has no index signature.
1111

12-
type VariableCommon = {
12+
interface VariableCommon {
1313
usage?: number,
1414
group?: string,
1515
name: string,
1616
key: string,
17-
modes?: { [mode: string]: TypeVariable }
17+
modes?: Record<string, TypeVariable>
1818
}
19-
export type StringVariable = { type: 'string', value: string }
20-
export type NumberVariable = { type: 'number', value: number }
21-
export type ColorVariable = { type: 'color', value: string, space: 'rgb' | 'hsl' }
19+
export interface StringVariable { type: 'string', value: string }
20+
export interface NumberVariable { type: 'number', value: number }
21+
export interface ColorVariable { type: 'color', value: string, space: 'rgb' | 'hsl' }
2222
export type TypeVariable = StringVariable | NumberVariable | ColorVariable
2323
export type Variable = TypeVariable & VariableCommon
2424

@@ -88,9 +88,9 @@ export default class MasterCSS {
8888
}
8989

9090
if (variables) {
91-
const unexecutedAliasVariable: Record<string, { [mode: string]: () => void }> = {}
91+
const unexecutedAliasVariable: Record<string, Record<string, () => void>> = {}
9292
const resolveVariable = (variableDefinition: VariableDefinition, name: string[], mode?: string) => {
93-
if (!variableDefinition === undefined || variableDefinition === null) return
93+
if (variableDefinition === undefined || variableDefinition === null) return
9494
const addVariable = (
9595
name: string[],
9696
variable: any,
@@ -577,7 +577,7 @@ export default class MasterCSS {
577577
for (let index = 0; index < sheet.cssRules.length; index++) {
578578
const eachCSSRule = sheet.cssRules[index]
579579
if (eachCSSRule === firstNative.cssRule) {
580-
for (let i = 0; i < rule.natives.length; i++) {
580+
for (const native of rule.natives) {
581581
sheet.deleteRule(index)
582582
}
583583
break
@@ -1036,12 +1036,8 @@ export default class MasterCSS {
10361036
if (sheet) {
10371037
let cssRule: CSSRule | undefined
10381038
if (initializing) {
1039-
for (let i = 0; i < sheet.cssRules.length; i++) {
1040-
const eachCSSRule = sheet.cssRules[i]
1041-
if (
1042-
eachCSSRule.constructor.name === 'CSSKeyframesRule'
1043-
&& (eachCSSRule as CSSKeyframesRule).name === eachKeyframeName
1044-
) {
1039+
for (const eachCSSRule of sheet.cssRules) {
1040+
if (eachCSSRule.constructor.name === 'CSSKeyframesRule' && (eachCSSRule as CSSKeyframesRule).name === eachKeyframeName) {
10451041
cssRule = eachCSSRule
10461042
break
10471043
}
@@ -1207,8 +1203,7 @@ export default class MasterCSS {
12071203
cssRule: variableCSSRule,
12081204
get text() {
12091205
const properties: string[] = []
1210-
for (let i = 0; i < variableCSSRule.style.length; i++) {
1211-
const property = variableCSSRule.style[i]
1206+
for (const property of variableCSSRule.style) {
12121207
properties.push(property + ':' + (variableCSSRule as CSSStyleRule).style.getPropertyValue(property))
12131208
}
12141209
return prefix + properties.join(';') + suffix

packages/core/src/rule.ts

+7-9
Original file line numberDiff line numberDiff line change
@@ -292,7 +292,7 @@ export class Rule {
292292
switch (featureName) {
293293
case 'max-width':
294294
case 'min-width':
295-
// eslint-disable-next-line no-case-declarations
295+
296296
if (typeof viewport === 'number') {
297297
atComponents.push({
298298
type: 'feature',
@@ -486,7 +486,7 @@ export class Rule {
486486
for (const eachValueComponent of valueComponents) {
487487
switch (eachValueComponent.type) {
488488
case 'function':
489-
// eslint-disable-next-line no-case-declarations
489+
490490
const functionDefinition = functions && functions[eachValueComponent.name]
491491
if (functionDefinition?.transform && !eachValueComponent.bypassTransform) {
492492
const result = functionDefinition.transform.call(
@@ -511,7 +511,7 @@ export class Rule {
511511
break
512512
// todo: 應挪到 parseValues 階段處理才能支援 variables: { x: 'calc(20vw-30px)' } 這種情況,並且解析上可能會比較合理、精簡
513513
case 'variable':
514-
// eslint-disable-next-line no-case-declarations
514+
515515
const variable = this.css.variables[eachValueComponent.name]
516516
if (variable) {
517517
const handleVariable = (
@@ -573,7 +573,7 @@ export class Rule {
573573
)
574574
break
575575
case 'color':
576-
// eslint-disable-next-line no-case-declarations
576+
577577
const alpha = eachValueComponent.alpha ? '/' + eachValueComponent.alpha : ''
578578
handleVariable(
579579
(variable) => {
@@ -832,7 +832,7 @@ export interface Rule extends RegisteredRule {
832832
stateToken: string
833833
atToken: string
834834
hasWhere: boolean
835-
valueComponents: Array<ValueComponent>
835+
valueComponents: ValueComponent[]
836836
}
837837

838838
export interface RegisteredRule {
@@ -877,7 +877,7 @@ export interface NativeRule {
877877
cssRule?: CSSRule
878878
}
879879

880-
export type MediaFeatureComponent = {
880+
export interface MediaFeatureComponent {
881881
type: string
882882
tokenType?: string
883883
operator?: string
@@ -887,8 +887,6 @@ export type MediaFeatureComponent = {
887887

888888
export interface MediaQuery {
889889
token: string;
890-
features: {
891-
[key: string]: MediaFeatureComponent
892-
}
890+
features: Record<string, MediaFeatureComponent>
893891
type?: string;
894892
}

packages/core/src/types/global.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
import type Core from '../core'
22

33
declare global {
4-
// eslint-disable-next-line no-var
4+
55
var masterCSSs: Core[]
6-
// eslint-disable-next-line no-var
6+
77
var MasterCSS: typeof Core
88
}

packages/core/src/utils/extend-config.ts

+1-2
Original file line numberDiff line numberDiff line change
@@ -46,8 +46,7 @@ export default function extendConfig(...configs: (Config | undefined)[]) {
4646
at: {},
4747
variables: {},
4848
}
49-
for (let i = 0; i < formattedConfigs.length; i++) {
50-
const currentFormattedConfig = formattedConfigs[i]
49+
for (const currentFormattedConfig of formattedConfigs) {
5150
for (const key in currentFormattedConfig) {
5251
switch (key) {
5352
case 'animations':

packages/create/.eslintrc.yml

-2
This file was deleted.

packages/create/eslint.config.mjs

+7
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
import common from '../../eslint.config.mjs'
2+
import techor from 'eslint-config-techor'
3+
4+
export default [
5+
...common,
6+
techor.configs.typescript,
7+
]

packages/create/package.json

+3-3
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
"scripts": {
55
"build": "techor build",
66
"dev": "pnpm build --watch",
7-
"lint": "eslint ./src",
7+
"lint": "eslint",
88
"type-check": "tsc --noEmit",
99
"test": "vitest"
1010
},
@@ -38,8 +38,8 @@
3838
},
3939
"dependencies": {
4040
"@master/css": "2.0.0-rc.38",
41-
"@techor/fs": "^3.0.22",
42-
"@techor/log": "^3.0.22",
41+
"@techor/fs": "^3.1.4",
42+
"@techor/log": "^3.1.4",
4343
"commander": "^12.0.0",
4444
"detect-package-manager": "^3.0.2",
4545
"giget": "^1.2.3",

packages/create/src/Options.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
export type Options = {
1+
export interface Options {
22
override: boolean
33
ext: 'mjs' | 'ts' | 'js'
44
pm: 'npm' | 'yarn' | 'pnpm' | 'bun'

0 commit comments

Comments
 (0)