Skip to content

Commit a2ace96

Browse files
committed
perf(ui): modernize code; fix some lint issues; temporarily disable gh worflow on build-types lint
1 parent aae9322 commit a2ace96

109 files changed

Lines changed: 537 additions & 610 deletions

File tree

Some content is hidden

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

.github/workflows/build-types.yml

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -65,9 +65,6 @@ jobs:
6565
- name: Install dependencies
6666
run: pnpm i
6767

68-
- name: Ensure types are formatted correctly
69-
run: pnpm lint:check
70-
7168
- name: Build the types
7269
run: pnpm build js types
7370

.oxfmtrc.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
"**/quasar.config.*.temporary.compiled*",
55
"**/.quasar/",
66

7+
"ui/dist/",
78
"ui/icon-set/svg-*.js",
89
"ui/lang/index.json",
910

.oxlintrc.json

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -35,13 +35,7 @@
3535
"unicorn/consistent-existence-index-check": "error",
3636
"unicorn/empty-brace-spaces": "error",
3737
"unicorn/error-message": "error",
38-
"unicorn/filename-case": [
39-
"error",
40-
{
41-
"cases": { "camelCase": true, "pascalCase": true },
42-
"ignore": ".d.ts$"
43-
}
44-
],
38+
"unicorn/filename-case": "off",
4539
"unicorn/no-await-expression-member": "error",
4640
"unicorn/no-console-spaces": "warn",
4741
"unicorn/numeric-separators-style": "error",

ui/.oxlintrc.json

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,5 +10,14 @@
1010
"__QUASAR_SSR_PWA__": "readonly"
1111
},
1212

13-
"ignorePatterns": ["icon-set/svg-*.js", "lang/index.json"]
13+
"ignorePatterns": ["icon-set/svg-*.js", "lang/index.json"],
14+
15+
"overrides": [
16+
{
17+
"files": ["**/*.test.js"],
18+
"rules": {
19+
"unicorn/consistent-function-scoping": "off"
20+
}
21+
}
22+
]
1423
}

ui/build/build.api.js

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -658,7 +658,7 @@ function encodeDefaultValue(val, isFunction) {
658658

659659
const arrowMatch = fn.match(functionRE)
660660
if (arrowMatch !== null) {
661-
return fn.substring(arrowMatch[1].length)
661+
return fn.slice(arrowMatch[1].length)
662662
}
663663
}
664664

@@ -737,11 +737,11 @@ function extractRuntimePropAttrs(runtimeProp) {
737737
runtimeTypes.push(capitalize(match[1]))
738738
}
739739

740-
if (fn.indexOf('Array.isArray') !== -1) {
740+
if (fn.includes('Array.isArray')) {
741741
runtimeTypes.push('Array')
742742
}
743743

744-
if (fn.indexOf('Object') !== -1) {
744+
if (fn.includes('Object')) {
745745
runtimeTypes.push('Object')
746746
}
747747

@@ -1073,7 +1073,7 @@ function parseObject({
10731073
)
10741074
}
10751075

1076-
if (itemName.indexOf('class') !== -1) {
1076+
if (itemName.includes('class')) {
10771077
if (obj.type === 'Object' && obj.tsType !== 'VueClassObjectProp') {
10781078
printErrorAndExit(
10791079
'object is class-type (Object form) but "tsType" prop is set to ' +
@@ -1088,7 +1088,7 @@ function parseObject({
10881088
`is set to "${obj.tsType}" instead of "VueClassProp":`
10891089
)
10901090
}
1091-
} else if (itemName.indexOf('style') !== -1) {
1091+
} else if (itemName.includes('style')) {
10921092
if (obj.type === 'Object' && obj.tsType !== 'VueStyleObjectProp') {
10931093
printErrorAndExit(
10941094
'object is style-type (Object form) but "tsType" prop is ' +
@@ -1206,7 +1206,7 @@ function parseAPI(file, apiType) {
12061206
}
12071207
handledTypes.push('value', 'arg')
12081208

1209-
const isComponent = banner.indexOf('component') !== -1
1209+
const isComponent = banner.includes('component')
12101210

12111211
for (const type in api) {
12121212
const targetApi = api[type]
@@ -1249,7 +1249,7 @@ function fillAPI(apiType, list, encodeFn) {
12491249

12501250
const componentPath = file.replace('.json', '.js')
12511251
const componentName = name.replace('.json', '.js')
1252-
const componentContent = fse.readFileSync(componentPath, 'utf-8')
1252+
const componentContent = fse.readFileSync(componentPath, 'utf8')
12531253

12541254
let RuntimeComponent
12551255

@@ -1316,7 +1316,7 @@ function fillAPI(apiType, list, encodeFn) {
13161316
const apiPropName = kebabCase(runtimePropName)
13171317
const apiEntry = apiProps[apiPropName]
13181318

1319-
if (runtimePropName.indexOf('-') !== -1) {
1319+
if (runtimePropName.includes('-')) {
13201320
logError(
13211321
`${componentName}: prop "${runtimePropName}" should be ` +
13221322
'in camelCase (found kebab-case)'
@@ -1439,7 +1439,7 @@ function fillAPI(apiType, list, encodeFn) {
14391439
if (isRuntimeFunction === true) {
14401440
const fn = runtimeDefaultValue.toString()
14411441

1442-
if (fn.indexOf('\n') !== -1) {
1442+
if (fn.includes('\n')) {
14431443
logError(
14441444
`${componentName}: prop "${runtimePropName}" -> "default" ` +
14451445
'should be a single line arrow function (found multiple lines)'
@@ -1555,7 +1555,7 @@ function fillAPI(apiType, list, encodeFn) {
15551555
hasError = true
15561556
}
15571557

1558-
if (runtimeEmitName.indexOf('-') !== -1) {
1558+
if (runtimeEmitName.includes('-')) {
15591559
logError(
15601560
`${componentName}: "emits" -> "${runtimeEmitName}" should be` +
15611561
' in camelCase (found kebab-case)'
@@ -1651,7 +1651,7 @@ function fillAPI(apiType, list, encodeFn) {
16511651
// copy API file to dest
16521652
writeFile(filePath, encodeFn(api))
16531653

1654-
const shortName = name.substring(0, name.length - 5)
1654+
const shortName = name.slice(0, -5)
16551655
list.push(shortName)
16561656

16571657
return {
@@ -1680,7 +1680,7 @@ function writeTransformAssetUrls(components, encodeFn) {
16801680
propName => api.props[propName].transformAssetUrls === true
16811681
)
16821682

1683-
if (props.length > 0) {
1683+
if (props.length !== 0) {
16841684
props = props.length > 1 ? props : props[0]
16851685

16861686
transformAssetUrls.tags[name] = props

ui/build/build.icon-sets.js

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ const svgIconSetBanner = setName => `
1313
const convert = str => str.replace(/(-\w)/g, m => m[1].toUpperCase())
1414
const materialConvert = (str, old, prefix) => {
1515
if (old !== '') {
16-
str = str.substring(old.length)
16+
str = str.slice(old.length)
1717
}
1818
return (prefix + str).replace(/(_\w)/g, m => m[1].toUpperCase())
1919
}
@@ -148,7 +148,7 @@ function splitContent(str) {
148148
function generateSvgFile(type) {
149149
const original = fse.readFileSync(
150150
resolveToRoot(`icon-set/${type.name}.js`),
151-
'utf-8'
151+
'utf8'
152152
)
153153
const { outsideOfExport, insideOfExport } = splitContent(original)
154154

@@ -166,7 +166,7 @@ function generateSvgFile(type) {
166166
.replace(/name: ""/, `name: 'svg-${type.name}'`)
167167

168168
const importString = Object.keys(importList)
169-
.filter(listName => importList[listName].length > 0)
169+
.filter(listName => importList[listName].length !== 0)
170170
.map(
171171
listName =>
172172
'import {\n ' +
@@ -189,7 +189,7 @@ function generateSvgFile(type) {
189189
let oldContent = ''
190190

191191
try {
192-
oldContent = fse.readFileSync(iconFile, 'utf-8')
192+
oldContent = fse.readFileSync(iconFile, 'utf8')
193193
} catch {}
194194

195195
return content.split(/[\n\r]+/).join('\n') !==

ui/build/build.types.js

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,8 @@ async function formatWithOxfmt(filePath, rawCode) {
1919
try {
2020
const { code } = await format(filePath, rawCode)
2121
return code
22-
} catch (error) {
23-
console.error(`Failed to format ${filePath}:`, error)
22+
} catch (err) {
23+
console.error(`Failed to format ${filePath}:`, err)
2424
process.exit(1)
2525
}
2626
}
@@ -63,7 +63,7 @@ function convertTypeVal(type, def) {
6363
if (def.values && type === 'String') {
6464
const narrowedValues = def.values.filter(v => !dontNarrowValues.includes(v))
6565

66-
if (narrowedValues.length) {
66+
if (narrowedValues.length !== 0) {
6767
return narrowedValues.join(' | ')
6868
}
6969
}
@@ -80,7 +80,7 @@ function convertTypeVal(type, def) {
8080
const lines = []
8181
propDefinitions.forEach(propDef => writeLines(lines, propDef, 2))
8282

83-
if (lines.length > 0) {
83+
if (lines.length !== 0) {
8484
return `{ ${lines.join('')} }${type === 'Array' ? '[]' : ''}`
8585
}
8686
}
@@ -152,7 +152,7 @@ function getPropDefinition({
152152
(isCompProps === true || isRestParam) &&
153153
name !== 'model-value' &&
154154
!definition.required &&
155-
propType.indexOf(' undefined') === -1
155+
!propType.includes(' undefined')
156156
) {
157157
propType += ' | undefined;'
158158
}
@@ -179,7 +179,7 @@ function getPropDefinition({
179179
jsDoc += ` * @returns ${returns.desc}\n`
180180
}
181181

182-
if (jsDoc.length > 0) {
182+
if (jsDoc.length !== 0) {
183183
jsDoc = '/**\n' + jsDoc + ' */\n'
184184
}
185185
}
@@ -328,6 +328,8 @@ function transformObject(definition, handler) {
328328
return result
329329
}
330330

331+
const getSafeInjectionKey = key => key.toUpperCase().replace('$', '')
332+
331333
function getIndexDts(apis, quasarLangIndex) {
332334
const contents = []
333335
const quasarTypeContents = []
@@ -439,7 +441,7 @@ function getIndexDts(apis, quasarLangIndex) {
439441
' * - ' + name + ':',
440442
' * - type: ' + getTypeVal(modifier),
441443
' * - description: ' + modifier.desc,
442-
...(modifier.examples && modifier.examples.length > 0
444+
...(modifier.examples && modifier.examples.length !== 0
443445
? [
444446
' * - examples:',
445447
...modifier.examples.map(
@@ -695,8 +697,6 @@ function getIndexDts(apis, quasarLangIndex) {
695697
}
696698
})
697699

698-
const getSafeInjectionKey = key => key.toUpperCase().replace('$', '')
699-
700700
// Write injection types
701701
for (const key in injections) {
702702
const injectionKey = getSafeInjectionKey(key)
@@ -832,7 +832,7 @@ function ensureTypeScriptValidity() {
832832
'tsconfig.json'
833833
)
834834
if (!tsConfigPath) {
835-
throw Error(resolvePath('tsconfig.json') + ' not found')
835+
throw new Error(resolvePath('tsconfig.json') + ' not found')
836836
}
837837
const { config } = typescript.readConfigFile(
838838
tsConfigPath,

ui/build/build.utils.js

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,7 @@ export const banner =
8686
' */\n'
8787

8888
process.on('exit', code => {
89-
if (code === 0 && tableData.length > 0) {
89+
if (code === 0 && tableData.length !== 0) {
9090
tableData.sort((a, b) =>
9191
a[0] === b[0] ? (a[1] < b[1] ? -1 : 1) : a[0] < b[0] ? -1 : 1
9292
)
@@ -135,7 +135,7 @@ function getDestinationInfo(dest) {
135135
return {
136136
banner: green('[js] '),
137137
tableEntryType: green('js'),
138-
toTable: dest.indexOf('dist/quasar') !== -1
138+
toTable: dest.includes('dist/quasar')
139139
}
140140
}
141141

@@ -198,17 +198,17 @@ export function writeFile(dest, code, zip) {
198198
}
199199

200200
export function readFile(file) {
201-
return fse.readFileSync(file, 'utf-8')
201+
return fse.readFileSync(file, 'utf8')
202202
}
203203

204204
export function readJsonFile(file) {
205-
return JSON.parse(fse.readFileSync(file, 'utf-8'))
205+
return JSON.parse(fse.readFileSync(file, 'utf8'))
206206
}
207207

208208
export function writeFileIfChanged(dest, newContent, zip) {
209209
let currentContent = ''
210210
try {
211-
currentContent = fse.readFileSync(dest, 'utf-8')
211+
currentContent = fse.readFileSync(dest, 'utf8')
212212
} catch {}
213213

214214
return newContent.split(/[\n\r]+/).join('\n') !==

ui/build/prepare-diff.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ export default function prepareDiff(locationPath) {
3535

3636
// Read the current (old) contents
3737
originalFiles.forEach(filePath => {
38-
originalsMap.set(filePath, fse.readFileSync(filePath, 'utf-8'))
38+
originalsMap.set(filePath, fse.readFileSync(filePath, 'utf8'))
3939
})
4040

4141
// Before exiting the process, read the new contents and output the diff
@@ -57,7 +57,7 @@ export default function prepareDiff(locationPath) {
5757
return
5858
}
5959

60-
const currentContent = fse.readFileSync(filePath, 'utf-8')
60+
const currentContent = fse.readFileSync(filePath, 'utf8')
6161
const originalContent = originalsMap.get(filePath)
6262

6363
if (originalContent !== currentContent) {

ui/build/script.build.css.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -117,8 +117,8 @@ export function buildCss(withDiff) {
117117
Promise.all([
118118
generateBase('src/css/index.sass'),
119119
generateAddon('src/css/flex-addon.sass')
120-
]).catch(e => {
121-
console.error(e)
120+
]).catch(err => {
121+
console.error(err)
122122
process.exit(1)
123123
})
124124
}

0 commit comments

Comments
 (0)