Skip to content

Commit

Permalink
style: replace eslint-plugin-vue-libs with standard config (vuejs#6148)
Browse files Browse the repository at this point in the history
  • Loading branch information
haoqunjiang authored Jan 6, 2021
1 parent ffc0686 commit 4378c8d
Show file tree
Hide file tree
Showing 35 changed files with 459 additions and 400 deletions.
19 changes: 9 additions & 10 deletions .eslintrc.js
Original file line number Diff line number Diff line change
@@ -1,23 +1,19 @@
module.exports = {
extends: [
'plugin:vue-libs/recommended'
'@vue/standard'
],
plugins: [
'node'
],
env: {
'jest': true
},
globals: {
name: 'off'
},
rules: {
'indent': ['error', 2, {
'MemberExpression': 'off'
indent: ['error', 2, {
MemberExpression: 'off'
}],
quotes: [2, 'single', { avoidEscape: true, allowTemplateLiterals: true }],
'quote-props': 'off',
'no-shadow': ['error'],
'node/no-extraneous-require': ['error', {
'allowModules': [
allowModules: [
'@vue/cli-service',
'@vue/cli-test-utils'
]
Expand All @@ -26,6 +22,9 @@ module.exports = {
overrides: [
{
files: ['**/__tests__/**/*.js', '**/cli-test-utils/**/*.js'],
env: {
jest: true
},
rules: {
'node/no-extraneous-require': 'off'
}
Expand Down
4 changes: 2 additions & 2 deletions packages/@vue/babel-preset-app/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -259,13 +259,13 @@ module.exports = (context, options = {}) => {
return {
sourceType: 'unambiguous',
overrides: [{
exclude: [/@babel[\/|\\\\]runtime/, /core-js/],
exclude: [/@babel[/|\\\\]runtime/, /core-js/],
presets,
plugins
}, {
// there are some untranspiled code in @babel/runtime
// https://github.com/babel/babel/issues/9903
include: [/@babel[\/|\\\\]runtime/],
include: [/@babel[/|\\\\]runtime/],
presets: [
[require('@babel/preset-env'), envOptions]
]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,3 @@ defineTest(__dirname, 'usePluginPreset', null, 'default')
defineTest(__dirname, 'usePluginPreset', null, 'customConfig')
defineTest(__dirname, 'usePluginPreset', null, 'require')
defineTest(__dirname, 'usePluginPreset', null, 'templateLiteral')

2 changes: 2 additions & 0 deletions packages/@vue/cli-plugin-babel/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@ function genTranspileDepRegex (transpileDependencies) {
} else if (dep instanceof RegExp) {
return dep.source
}

throw new Error('transpileDependencies only accepts an array of string or regular expressions')
})
return deps.length ? new RegExp(deps.join('|')) : null
}
Expand Down
12 changes: 7 additions & 5 deletions packages/@vue/cli-plugin-e2e-nightwatch/nightwatch.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ const defaultSettings = {
test_settings: {
default: {
detailed_output: !concurrentMode,
launch_url: '${VUE_DEV_SERVER_URL}'
launch_url: '${VUE_DEV_SERVER_URL}' // eslint-disable-line no-template-curly-in-string
},

chrome: {
Expand All @@ -56,10 +56,12 @@ const defaultSettings = {
}
}
},
webdriver: useSelenium ? {} : {
server_path: geckodriver.path,
port: 4444
}
webdriver: useSelenium
? {}
: {
server_path: geckodriver.path,
port: 4444
}
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,13 @@ test('should add types to existing tsconfig.json', async () => {
}
}
})
await write('tsconfig.json', JSON.stringify({ compilerOptions: { types: ['some-type'] }}))
await write('tsconfig.json', JSON.stringify({ compilerOptions: { types: ['some-type'] } }))

const invoke = require('@vue/cli/lib/invoke')
await invoke('e2e-webdriverio', { webdrivers: ['chrome'] }, dir)

const tsconfig = await read('tsconfig.json')
expect(tsconfig).toMatch(/\r?\n$/)
expect(JSON.parse(tsconfig)['compilerOptions']['types'])
expect(JSON.parse(tsconfig).compilerOptions.types)
.toEqual(['some-type', 'mocha', '@wdio/mocha-framework', '@wdio/sync'])
})
2 changes: 1 addition & 1 deletion packages/@vue/cli-plugin-eslint/generator/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ module.exports = (api, { config, lintOn = [] }, rootOptions, invoking) => {
'pre-commit': 'lint-staged'
}
const extensions = require('../eslintOptions').extensions(api)
.map(ext => ext.replace(/^\./, '')) // remove the leading `.`
.map(ext => ext.replace(/^\./, '')) // remove the leading `.`
pkg['lint-staged'] = {
[`*.{${extensions.join(',')}}`]: 'vue-cli-service lint'
}
Expand Down
2 changes: 1 addition & 1 deletion packages/@vue/cli-plugin-pwa/__tests__/pwaPlugin.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ test('pwa', async () => {
browser = launched.browser

// workbox plugin fetches scripts from CDN so it takes a while...
await new Promise(r => setTimeout(r, process.env.CI ? 5000 : 2000))
await new Promise(resolve => setTimeout(resolve, process.env.CI ? 5000 : 2000))
const logs = launched.logs
expect(logs.some(msg => msg.match(/Content has been cached for offline use/))).toBe(true)
expect(logs.some(msg => msg.match(/App is being served from cache by a service worker/))).toBe(true)
Expand Down
6 changes: 3 additions & 3 deletions packages/@vue/cli-plugin-pwa/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -54,9 +54,9 @@ module.exports = (api, options) => {
]
}

const defaultGenerateSWOptions = workboxPluginMode === 'GenerateSW' ? {
cacheId: name
} : {}
const defaultGenerateSWOptions = workboxPluginMode === 'GenerateSW'
? { cacheId: name }
: {}

const workBoxConfig = Object.assign(defaultOptions, defaultGenerateSWOptions, userOptions.workboxOptions)

Expand Down
4 changes: 2 additions & 2 deletions packages/@vue/cli-plugin-pwa/ui.js
Original file line number Diff line number Diff line change
Expand Up @@ -129,15 +129,15 @@ module.exports = api => {
// Update app manifest (only when there's a manifest.json file,
// otherwise it will be inferred from options in vue.config.js)
if (data.manifest) {
const name = result['name']
const name = result.name
if (name) {
onWriteApi.setData('manifest', {
name,
short_name: name
})
}

const themeColor = result['themeColor']
const themeColor = result.themeColor
if (themeColor) {
onWriteApi.setData('manifest', {
theme_color: themeColor
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ test('generate files', async () => {
expect(files['src/main.js']).toBeFalsy()
expect(files['src/App.vue']).toMatch('<script lang="ts">')
// checks that the Home.vue file has not been created, even empty
expect(files.hasOwnProperty('src/views/Home.vue')).toBeFalsy()
expect(Object.prototype.hasOwnProperty.call(files, 'src/views/Home.vue')).toBeFalsy()
})

test('classComponent', async () => {
Expand Down Expand Up @@ -77,7 +77,7 @@ test('use with router', async () => {
options: {}
}
])
expect(files['src/views/Home.vue']).toMatch('<div class=\"home\">')
expect(files['src/views/Home.vue']).toMatch('<div class="home">')
})

test('tsconfig.json should be valid json', async () => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,8 @@ module.exports = function migrateComponentType (file, api) {
) {
return false
}

return true
})
if (defineComponentUsages.length === 0) {
tsmodule
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -150,12 +150,12 @@ test('add types to existing tsconfig.json', async () => {
'@vue/cli-plugin-unit-jest': {}
}
})
await write('tsconfig.json', JSON.stringify({ compilerOptions: { types: ['some-type'] }}))
await write('tsconfig.json', JSON.stringify({ compilerOptions: { types: ['some-type'] } }))

const invoke = require('@vue/cli/lib/invoke')
await invoke('unit-jest', {}, dir)

const tsconfig = await read('tsconfig.json')
expect(tsconfig).toMatch(/\r?\n$/)
expect(JSON.parse(tsconfig)['compilerOptions']['types']).toEqual(['some-type', 'jest'])
expect(JSON.parse(tsconfig).compilerOptions.types).toEqual(['some-type', 'jest'])
}, 30000)
Original file line number Diff line number Diff line change
Expand Up @@ -147,12 +147,12 @@ test('add types to existing tsconfig.json', async () => {
'@vue/cli-plugin-unit-mocha': {}
}
})
await write('tsconfig.json', JSON.stringify({ compilerOptions: { types: ['some-type'] }}))
await write('tsconfig.json', JSON.stringify({ compilerOptions: { types: ['some-type'] } }))

const invoke = require('@vue/cli/lib/invoke')
await invoke('unit-mocha', {}, dir)

const tsconfig = await read('tsconfig.json')
expect(tsconfig).toMatch(/\r?\n$/)
expect(JSON.parse(tsconfig)['compilerOptions']['types']).toEqual(['some-type', 'mocha', 'chai'])
expect(JSON.parse(tsconfig).compilerOptions.types).toEqual(['some-type', 'mocha', 'chai'])
}, 30000)
14 changes: 8 additions & 6 deletions packages/@vue/cli-plugin-unit-mocha/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -67,19 +67,21 @@ module.exports = api => {
'--webpack-config',
require.resolve('@vue/cli-service/webpack.config.js'),
...rawArgv,
...(hasInlineFilesGlob ? [] : [
api.hasPlugin('typescript')
? `tests/unit/**/*.spec.ts`
: `tests/unit/**/*.spec.js`
])
...(hasInlineFilesGlob
? []
: [
api.hasPlugin('typescript')
? `tests/unit/**/*.spec.ts`
: `tests/unit/**/*.spec.js`
])
]

return new Promise((resolve, reject) => {
const child = execa('node', argv, { stdio: 'inherit' })
child.on('error', reject)
child.on('exit', code => {
if (code !== 0) {
reject(`mochapack exited with code ${code}.`)
reject(new Error(`mochapack exited with code ${code}.`))
} else {
resolve()
}
Expand Down
2 changes: 1 addition & 1 deletion packages/@vue/cli-service/__tests__/Service.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,7 @@ test('keep publicPath when empty', () => {
})

test('load project options from vue.config.js', () => {
fs.writeFileSync(path.resolve('/', 'vue.config.js'), '') // only to ensure fs.existsSync returns true
fs.writeFileSync(path.resolve('/', 'vue.config.js'), '') // only to ensure fs.existsSync returns true
jest.mock(path.resolve('/', 'vue.config.js'), () => ({ lintOnSave: false }), { virtual: true })
mockPkg({
vue: {
Expand Down
3 changes: 1 addition & 2 deletions packages/@vue/cli-service/__tests__/css.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ test('production defaults', () => {
})

test('override postcss config', () => {
const config = genConfig({ postcss: {}})
const config = genConfig({ postcss: {} })
LANGS.forEach(lang => {
const loader = lang === 'css' ? [] : LOADERS[lang]
expect(findLoaders(config, lang)).toEqual(['vue-style', 'css', 'postcss'].concat(loader))
Expand Down Expand Up @@ -393,4 +393,3 @@ test('should use dart sass implementation whenever possible', () => {
expect(findOptions(config, 'scss', 'sass')).toMatchObject({ implementation: require('sass') })
expect(findOptions(config, 'sass', 'sass')).toMatchObject({ implementation: require('sass') })
})

1 change: 0 additions & 1 deletion packages/@vue/cli-service/__tests__/serve.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -192,4 +192,3 @@ test('use a single websocket connection for HMR', async () => {
}
)
})

2 changes: 1 addition & 1 deletion packages/@vue/cli-service/lib/PluginAPI.js
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ class PluginAPI {
fn = opts
opts = null
}
this.service.commands[name] = { fn, opts: opts || {}}
this.service.commands[name] = { fn, opts: opts || {} }
}

/**
Expand Down
2 changes: 1 addition & 1 deletion packages/@vue/cli-service/lib/Service.js
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ module.exports = class Service {
// resolve the default mode to use for each command
// this is provided by plugins as module.exports.defaultModes
// so we can get the information without actually applying the plugin.
this.modes = this.plugins.reduce((modes, { apply: { defaultModes }}) => {
this.modes = this.plugins.reduce((modes, { apply: { defaultModes } }) => {
return Object.assign(modes, defaultModes)
}, {})
}
Expand Down
2 changes: 1 addition & 1 deletion packages/@vue/cli-service/lib/commands/build/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -204,7 +204,7 @@ async function build (args, api, options) {
}

if (stats.hasErrors()) {
return reject(`Build failed with errors.`)
return reject(new Error('Build failed with errors.'))
}

if (!args.silent) {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
/* eslint-disable no-var */
// This file is imported into lib/wc client bundles.

if (typeof window !== 'undefined') {
Expand Down
4 changes: 2 additions & 2 deletions packages/@vue/cli-service/lib/config/css.js
Original file line number Diff line number Diff line change
Expand Up @@ -65,8 +65,8 @@ module.exports = (api, rootOptions) => {
? './'
: '../'.repeat(
extractOptions.filename
.replace(/^\.[\/\\]/, '')
.split(/[\/\\]/g)
.replace(/^\.[/\\]/, '')
.split(/[/\\]/g)
.length - 1
)

Expand Down
2 changes: 1 addition & 1 deletion packages/@vue/cli-service/lib/util/isAbsoluteUrl.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
module.exports = function isAbsoluteUrl (url) {
// A URL is considered absolute if it begins with "<scheme>://" or "//"
return /^([a-z][a-z\d\+\-\.]*:)?\/\//i.test(url)
return /^([a-z][a-z\d+\-.]*:)?\/\//i.test(url)
}
6 changes: 3 additions & 3 deletions packages/@vue/cli-service/lib/util/prepareProxy.js
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,7 @@ module.exports = function prepareProxy (proxy, appPublicFolder) {
// Otherwise, proxy is an object so create an array of proxies to pass to webpackDevServer
return Object.keys(proxy).map(context => {
const config = proxy[context]
if (!config.hasOwnProperty('target')) {
if (!Object.prototype.hasOwnProperty.call(config, 'target')) {
console.log(
chalk.red(
'When `proxy` in package.json is an object, each `context` object must have a ' +
Expand All @@ -135,7 +135,7 @@ module.exports = function prepareProxy (proxy, appPublicFolder) {
}

function resolveLoopback (proxy) {
const o = url.parse(proxy)
const o = new url.URL(proxy)
o.host = undefined
if (o.hostname !== 'localhost') {
return proxy
Expand All @@ -148,7 +148,7 @@ function resolveLoopback (proxy) {
o.hostname = address.ipv6() ? '::1' : '127.0.0.1';
} catch (_ignored) {
o.hostname = '127.0.0.1';
}*/
} */

try {
// Check if we're on a network; if we are, chances are we can resolve
Expand Down
2 changes: 1 addition & 1 deletion packages/@vue/cli-service/lib/webpack/ModernModePlugin.js
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ class ModernModePlugin {
const fullSafariFixPath = path.join(compilation.options.output.publicPath, safariFixPath)
compilation.assets[safariFixPath] = {
source: function () {
return new Buffer(safariFix)
return Buffer.from(safariFix)
},
size: function () {
return Buffer.byteLength(safariFix)
Expand Down
1 change: 1 addition & 0 deletions packages/@vue/cli-shared-utils/lib/module.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ const semver = require('semver')
// https://github.com/benmosher/eslint-plugin-import/pull/1602
// Polyfill Node's `Module.createRequireFromPath` if not present (added in Node v10.12.0)
// Use `Module.createRequire` if available (added in Node v12.2.0)
// eslint-disable-next-line node/no-deprecated-api
const createRequire = Module.createRequire || Module.createRequireFromPath || function (filename) {
const mod = new Module(filename, null)
mod.filename = filename
Expand Down
3 changes: 1 addition & 2 deletions packages/@vue/cli-shared-utils/lib/openBrowser.js
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,6 @@ function executeNodeScript (scriptPath, url) {
)
console.log(chalk.cyan(scriptPath) + ' exited with code ' + code + '.')
console.log()
return
}
})
return true
Expand Down Expand Up @@ -95,7 +94,7 @@ function startBrowserProcess (browser, url) {
// Fallback to open
// (It will always open new tab)
try {
var options = { app: browser, url: true }
const options = { app: browser, url: true }
open(url, options).catch(() => {}) // Prevent `unhandledRejection` error.
return true
} catch (err) {
Expand Down
Loading

0 comments on commit 4378c8d

Please sign in to comment.