mirror of
https://github.com/the1812/Bilibili-Evolved.git
synced 2025-11-04 21:22:45 +08:00
Enable ESLint on webpack files
This commit is contained in:
parent
4cb75cd8ce
commit
432fdc0289
@ -1,7 +1,7 @@
|
||||
webpack/
|
||||
packages/
|
||||
typings/
|
||||
dist/
|
||||
dev/
|
||||
node_modules/
|
||||
*.config.*
|
||||
.eslintrc.*
|
||||
|
||||
43
.eslintrc.js
43
.eslintrc.js
@ -18,10 +18,7 @@ module.exports = {
|
||||
parser: '@typescript-eslint/parser',
|
||||
sourceType: 'module',
|
||||
},
|
||||
plugins: [
|
||||
'vue',
|
||||
'@typescript-eslint',
|
||||
],
|
||||
plugins: ['vue', '@typescript-eslint'],
|
||||
rules: {
|
||||
'import/no-unresolved': 'off',
|
||||
'import/extensions': 'off',
|
||||
@ -38,7 +35,8 @@ module.exports = {
|
||||
'@typescript-eslint/no-explicit-any': 'off',
|
||||
'@typescript-eslint/no-use-before-define': ['error'],
|
||||
'@typescript-eslint/no-redeclare': 'error',
|
||||
'@typescript-eslint/naming-convention': ['error',
|
||||
'@typescript-eslint/naming-convention': [
|
||||
'error',
|
||||
{
|
||||
selector: 'enumMember',
|
||||
format: ['PascalCase'],
|
||||
@ -65,7 +63,7 @@ module.exports = {
|
||||
'no-await-in-loop': 'off',
|
||||
'no-restricted-syntax': 'off',
|
||||
'no-useless-escape': 'off',
|
||||
'no-empty-function': ['error', { 'allow': ['constructors'] }],
|
||||
'no-empty-function': ['error', { allow: ['constructors'] }],
|
||||
'no-return-assign': ['error', 'except-parens'],
|
||||
'no-redeclare': 'off',
|
||||
'no-script-url': 'off',
|
||||
@ -76,33 +74,34 @@ module.exports = {
|
||||
|
||||
'arrow-parens': ['error', 'as-needed'],
|
||||
'object-curly-newline': 'off',
|
||||
'semi': ['error', 'never'],
|
||||
semi: ['error', 'never'],
|
||||
'linebreak-style': 'off',
|
||||
'camelcase': 'off',
|
||||
camelcase: 'off',
|
||||
'lines-between-class-members': 'off',
|
||||
'radix': ['error', 'as-needed'],
|
||||
radix: ['error', 'as-needed'],
|
||||
'max-len': 'error',
|
||||
'max-classes-per-file': 'off',
|
||||
'prefer-destructuring': ['error',
|
||||
'prefer-destructuring': [
|
||||
'error',
|
||||
{
|
||||
'VariableDeclarator': {
|
||||
'array': false,
|
||||
'object': true
|
||||
VariableDeclarator: {
|
||||
array: false,
|
||||
object: true,
|
||||
},
|
||||
AssignmentExpression: {
|
||||
array: false,
|
||||
object: false,
|
||||
},
|
||||
'AssignmentExpression': {
|
||||
'array': false,
|
||||
'object': false
|
||||
}
|
||||
},
|
||||
],
|
||||
'curly': ['error', 'all'],
|
||||
curly: ['error', 'all'],
|
||||
},
|
||||
overrides: [
|
||||
{
|
||||
files: ['*.vue', 'shims.d.ts'],
|
||||
files: ['*.vue', 'shims.d.ts', 'webpack/**/*.ts', 'registry/webpack/**/*.ts'],
|
||||
rules: {
|
||||
'import/no-default-export': 'off',
|
||||
}
|
||||
}
|
||||
]
|
||||
},
|
||||
},
|
||||
],
|
||||
}
|
||||
|
||||
@ -6,10 +6,10 @@
|
||||
"author": "Grant Howard, Coulomb-G",
|
||||
"license": "MIT",
|
||||
"scripts": {
|
||||
"build-core": "webpack --config ./webpack/webpack.prod.js --bail",
|
||||
"build-features": "webpack --config ./registry/webpack/all.js --bail",
|
||||
"lint": "eslint --config ./.eslintrc.js --quiet --fix \"src/**/*.@(js|ts|vue)\" \"registry/lib/**/*.@(js|ts|vue)\"",
|
||||
"lint-check": "eslint --config ./.eslintrc.js \"src/**/*.@(js|ts|vue)\" \"registry/lib/**/*.@(js|ts|vue)\"",
|
||||
"build-core": "webpack --config ./webpack/webpack.prod.ts --bail",
|
||||
"build-features": "webpack --config ./registry/webpack/all.ts --bail",
|
||||
"lint": "eslint --config ./.eslintrc.js --quiet --fix \"./**/*.@(js|ts|vue)\"",
|
||||
"lint-check": "eslint --config ./.eslintrc.js \"./**/*.@(js|ts|vue)\"",
|
||||
"type": "tsc -p tsconfig.type-check.json --noEmit"
|
||||
},
|
||||
"devDependencies": {
|
||||
|
||||
@ -1,8 +1,6 @@
|
||||
import { builders } from './build'
|
||||
|
||||
export default async () => {
|
||||
return [
|
||||
...(await builders.component({ buildAll: true })),
|
||||
...(await builders.plugin({ buildAll: true })),
|
||||
]
|
||||
}
|
||||
export default async () => [
|
||||
...(await builders.component({ buildAll: true })),
|
||||
...(await builders.plugin({ buildAll: true })),
|
||||
]
|
||||
|
||||
@ -1,10 +1,10 @@
|
||||
import { buildByEntry } from './config'
|
||||
import glob from 'glob'
|
||||
import { buildByEntry } from './config'
|
||||
|
||||
export const builders = Object.fromEntries(['component', 'plugin', 'doc'].map(type => {
|
||||
const src = `./registry/lib/${type}s/`
|
||||
return [type, async ({ buildAll = false } = {}) => {
|
||||
const entries = glob.sync(src + '**/index.ts')
|
||||
const entries = glob.sync(`${src}**/index.ts`)
|
||||
|
||||
if (buildAll) {
|
||||
console.log(`[build all] discovered ${entries.length} ${type}s`)
|
||||
@ -13,7 +13,7 @@ export const builders = Object.fromEntries(['component', 'plugin', 'doc'].map(ty
|
||||
|
||||
let entry: string
|
||||
if (entries.length > 1) {
|
||||
const { AutoComplete } = require('enquirer')
|
||||
const { AutoComplete } = await import('enquirer')
|
||||
const prompt = new AutoComplete({
|
||||
name: 'path',
|
||||
message: 'Select build target',
|
||||
|
||||
@ -1,13 +1,17 @@
|
||||
import { getDefaultConfig } from '../../webpack/webpack.config'
|
||||
import path from 'path'
|
||||
import { getId } from '../lib/id'
|
||||
import lodash from 'lodash'
|
||||
import { Configuration } from 'webpack'
|
||||
import { getDefaultConfig } from '../../webpack/webpack.config'
|
||||
import { getId } from '../lib/id'
|
||||
|
||||
export const buildByEntry = ({ src, type, entry }: { src: string; type: string; entry: string }) => {
|
||||
export const buildByEntry = (
|
||||
params: { src: string; type: string; entry: string },
|
||||
) => {
|
||||
// const match = entry.match(/\/?registry\/dist\/([^\/]+)\/(.+)\/index\.ts/)
|
||||
// if (!match) {
|
||||
// throw new Error(`Invalid entry path: ${entry}`)
|
||||
// }
|
||||
const { src, type, entry } = params
|
||||
const id = getId(src, entry)
|
||||
const defaultConfig = getDefaultConfig(path.resolve('./registry/lib/'))
|
||||
const config: Configuration = {
|
||||
@ -29,7 +33,6 @@ export const buildByEntry = ({ src, type, entry }: { src: string; type: string;
|
||||
externals: [
|
||||
...(defaultConfig.externals as any[]),
|
||||
({ request }, callback) => {
|
||||
const lodash = require('lodash')
|
||||
const regexMatch = (regex: RegExp, base: string[]) => {
|
||||
const match = request.match(regex)
|
||||
if (match) {
|
||||
@ -68,7 +71,7 @@ export const buildByEntry = ({ src, type, entry }: { src: string; type: string;
|
||||
}
|
||||
}
|
||||
return callback()
|
||||
}
|
||||
},
|
||||
],
|
||||
}
|
||||
return config
|
||||
|
||||
@ -1,10 +1,8 @@
|
||||
import { builders } from './build'
|
||||
import path from 'path'
|
||||
import { builders } from './build'
|
||||
|
||||
export default builders.doc().then(configs => {
|
||||
return configs.map(config => {
|
||||
config.output.path = path.resolve(`./registry/dist/`)
|
||||
config.output.filename = 'doc.js'
|
||||
return config
|
||||
})
|
||||
})
|
||||
export default builders.doc().then(configs => configs.map(config => {
|
||||
config.output.path = path.resolve('./registry/dist/')
|
||||
config.output.filename = 'doc.js'
|
||||
return config
|
||||
}))
|
||||
|
||||
3
src/shims.d.ts
vendored
3
src/shims.d.ts
vendored
@ -23,3 +23,6 @@ declare module '*.svg' {
|
||||
const svg: string
|
||||
export default svg
|
||||
}
|
||||
declare module 'enquirer' {
|
||||
export const AutoComplete: any
|
||||
}
|
||||
|
||||
@ -1,10 +1,10 @@
|
||||
import { runtimeInfo } from '../compilation-info/runtime'
|
||||
import { commitHash } from '../compilation-info/git'
|
||||
import {
|
||||
objectProperty,
|
||||
identifier,
|
||||
stringLiteral,
|
||||
} from '@babel/types'
|
||||
import { runtimeInfo } from '../compilation-info/runtime'
|
||||
import { commitHash } from '../compilation-info/git'
|
||||
import { InjectMetadataAction } from './types'
|
||||
|
||||
export const injectCoreInfo: InjectMetadataAction = () => [
|
||||
|
||||
@ -1,6 +1,5 @@
|
||||
import { existsSync, readFileSync } from 'fs'
|
||||
import { basename, dirname, join } from 'path'
|
||||
import { InjectMetadataAction } from './types'
|
||||
import { glob } from 'glob'
|
||||
import {
|
||||
objectProperty,
|
||||
@ -8,6 +7,7 @@ import {
|
||||
identifier,
|
||||
stringLiteral,
|
||||
} from '@babel/types'
|
||||
import { InjectMetadataAction } from './types'
|
||||
|
||||
export const injectDescription: InjectMetadataAction = ({ filename }) => {
|
||||
const folder = dirname(filename)
|
||||
|
||||
@ -1,5 +1,4 @@
|
||||
import { basename, dirname } from 'path'
|
||||
import { InjectMetadataAction } from './types'
|
||||
import { glob } from 'glob'
|
||||
import {
|
||||
ObjectProperty,
|
||||
@ -11,6 +10,7 @@ import {
|
||||
arrowFunctionExpression,
|
||||
stringLiteral,
|
||||
} from '@babel/types'
|
||||
import { InjectMetadataAction } from './types'
|
||||
|
||||
export const injectI18n: InjectMetadataAction = ({ filename }) => {
|
||||
const folder = dirname(filename)
|
||||
|
||||
@ -11,45 +11,42 @@ const injectActions: InjectMetadataAction[] = [
|
||||
injectI18n,
|
||||
]
|
||||
|
||||
export const injectMetadata = (): PluginObj => {
|
||||
return {
|
||||
visitor: {
|
||||
ExportNamedDeclaration(path, state) {
|
||||
const { filename } = state.file.opts
|
||||
const isFromRegistry = filename.startsWith(
|
||||
nodePath.resolve('./registry'),
|
||||
)
|
||||
const isFromCore = filename.startsWith(
|
||||
nodePath.resolve('./src/components'),
|
||||
) || filename.startsWith(
|
||||
nodePath.resolve('./src/plugins'),
|
||||
)
|
||||
const isEntryFile = nodePath.basename(filename) === 'index.ts'
|
||||
if (!((isFromRegistry || isFromCore) && isEntryFile)) {
|
||||
export const injectMetadata = (): PluginObj => ({
|
||||
visitor: {
|
||||
ExportNamedDeclaration(path, state) {
|
||||
const { filename } = state.file.opts
|
||||
const isFromRegistry = filename.startsWith(
|
||||
nodePath.resolve('./registry'),
|
||||
)
|
||||
const isFromCore = filename.startsWith(
|
||||
nodePath.resolve('./src/components'),
|
||||
) || filename.startsWith(
|
||||
nodePath.resolve('./src/plugins'),
|
||||
)
|
||||
const isEntryFile = nodePath.basename(filename) === 'index.ts'
|
||||
if (!((isFromRegistry || isFromCore) && isEntryFile)) {
|
||||
return
|
||||
}
|
||||
const { node } = path
|
||||
if (node.declaration?.type !== 'VariableDeclaration') {
|
||||
return
|
||||
}
|
||||
node.declaration.declarations?.forEach(d => {
|
||||
const isNameValid = d.id?.type === 'Identifier' && ['component', 'plugin'].includes(d.id.name)
|
||||
if (!isNameValid) {
|
||||
return
|
||||
}
|
||||
const { node } = path
|
||||
if (node.declaration?.type !== 'VariableDeclaration') {
|
||||
const targetExpression = d.init.type === 'CallExpression' ? d.init.arguments[0] : d.init
|
||||
if (targetExpression.type !== 'ObjectExpression') {
|
||||
return
|
||||
}
|
||||
node.declaration.declarations?.forEach(d => {
|
||||
const isNameValid = d.id?.type === 'Identifier' && ['component', 'plugin'].includes(d.id.name)
|
||||
if (!isNameValid) {
|
||||
return
|
||||
}
|
||||
const targetExpression =
|
||||
d.init.type === 'CallExpression' ? d.init.arguments[0] : d.init
|
||||
if (targetExpression.type !== 'ObjectExpression') {
|
||||
return
|
||||
}
|
||||
targetExpression.properties.push(
|
||||
...injectActions.flatMap(action => action({
|
||||
expression: targetExpression,
|
||||
filename,
|
||||
})),
|
||||
)
|
||||
})
|
||||
},
|
||||
targetExpression.properties.push(
|
||||
...injectActions.flatMap(action => action({
|
||||
expression: targetExpression,
|
||||
filename,
|
||||
})),
|
||||
)
|
||||
})
|
||||
},
|
||||
}
|
||||
}
|
||||
},
|
||||
})
|
||||
|
||||
@ -26,5 +26,5 @@ export const sassLoader: RuleSetUseItem = {
|
||||
},
|
||||
}
|
||||
|
||||
export const cssStyleLoaders = [ cssLoader, postCssLoader ]
|
||||
export const sassStyleLoaders = [ cssLoader, postCssLoader, sassLoader ]
|
||||
export const cssStyleLoaders = [cssLoader, postCssLoader]
|
||||
export const sassStyleLoaders = [cssLoader, postCssLoader, sassLoader]
|
||||
|
||||
@ -1,7 +1,6 @@
|
||||
import webpack from 'webpack'
|
||||
import webpack, { Configuration } from 'webpack'
|
||||
import { getBanner, getDefaultConfig } from './webpack.config'
|
||||
import previewMeta from '../src/client/bilibili-evolved.preview.meta.json'
|
||||
import { Configuration } from 'webpack'
|
||||
|
||||
const previewConfig = Object.assign(getDefaultConfig(), {
|
||||
entry: './src/client/bilibili-evolved.ts',
|
||||
|
||||
Loading…
Reference in New Issue
Block a user