Skip to content
/ vue-cli Public

style: replace eslint-plugin-vue-libs with standard config #6148

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 5 commits into from
Jan 6, 2021
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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'
]
@@ -26,6 +22,9 @@ module.exports = {
overrides: [
{
files: ['**/__tests__/**/*.js', '**/cli-test-utils/**/*.js'],
env: {
jest: true
},
rules: {
'node/no-extraneous-require': 'off'
}
4 changes: 2 additions & 2 deletions packages/@vue/babel-preset-app/index.js
Original file line number Diff line number Diff line change
@@ -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]
]
Original file line number Diff line number Diff line change
@@ -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
@@ -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
}
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
@@ -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: {
@@ -56,10 +56,12 @@ const defaultSettings = {
}
}
},
webdriver: useSelenium ? {} : {
server_path: geckodriver.path,
port: 4444
}
webdriver: useSelenium
? {}
: {
server_path: geckodriver.path,
port: 4444
}
}
}
}
Original file line number Diff line number Diff line change
@@ -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
@@ -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'
}
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
@@ -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)
6 changes: 3 additions & 3 deletions packages/@vue/cli-plugin-pwa/index.js
Original file line number Diff line number Diff line change
@@ -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)

4 changes: 2 additions & 2 deletions packages/@vue/cli-plugin-pwa/ui.js
Original file line number Diff line number Diff line change
@@ -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
Original file line number Diff line number Diff line change
@@ -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 () => {
@@ -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 () => {
Original file line number Diff line number Diff line change
@@ -80,6 +80,8 @@ module.exports = function migrateComponentType (file, api) {
) {
return false
}

return true
})
if (defineComponentUsages.length === 0) {
tsmodule
Original file line number Diff line number Diff line change
@@ -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
@@ -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
@@ -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()
}
2 changes: 1 addition & 1 deletion packages/@vue/cli-service/__tests__/Service.spec.js
Original file line number Diff line number Diff line change
@@ -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: {
3 changes: 1 addition & 2 deletions packages/@vue/cli-service/__tests__/css.spec.js
Original file line number Diff line number Diff line change
@@ -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))
@@ -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
@@ -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
@@ -84,7 +84,7 @@ class PluginAPI {
fn = opts
opts = null
}
this.service.commands[name] = { fn, opts: opts || {}}
this.service.commands[name] = { fn, opts: opts || {} }
}

/**
2 changes: 1 addition & 1 deletion packages/@vue/cli-service/lib/Service.js
Original file line number Diff line number Diff line change
@@ -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)
}, {})
}
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
@@ -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) {
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') {
4 changes: 2 additions & 2 deletions packages/@vue/cli-service/lib/config/css.js
Original file line number Diff line number Diff line change
@@ -65,8 +65,8 @@ module.exports = (api, rootOptions) => {
? './'
: '../'.repeat(
extractOptions.filename
.replace(/^\.[\/\\]/, '')
.split(/[\/\\]/g)
.replace(/^\.[/\\]/, '')
.split(/[/\\]/g)
.length - 1
)

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
@@ -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 ' +
@@ -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
@@ -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
2 changes: 1 addition & 1 deletion packages/@vue/cli-service/lib/webpack/ModernModePlugin.js
Original file line number Diff line number Diff line change
@@ -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)
1 change: 1 addition & 0 deletions packages/@vue/cli-shared-utils/lib/module.js
Original file line number Diff line number Diff line change
@@ -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
3 changes: 1 addition & 2 deletions packages/@vue/cli-shared-utils/lib/openBrowser.js
Original file line number Diff line number Diff line change
@@ -54,7 +54,6 @@ function executeNodeScript (scriptPath, url) {
)
console.log(chalk.cyan(scriptPath) + ' exited with code ' + code + '.')
console.log()
return
}
})
return true
@@ -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) {
726 changes: 390 additions & 336 deletions packages/@vue/cli/__tests__/Generator.spec.js

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions packages/@vue/cli/__tests__/invoke.spec.js
Original file line number Diff line number Diff line change
@@ -7,7 +7,7 @@ const create = require('@vue/cli-test-utils/createTestProject')

const parseJS = file => {
const res = {}
;(new Function('module', file))(res)
;(new Function('module', file))(res) // eslint-disable-line no-new-func
return res.exports
}

@@ -150,7 +150,7 @@ extends:
})

test('invoking a plugin that renames files', async () => {
const project = await create(`invoke-rename`, { plugins: {}})
const project = await create(`invoke-rename`, { plugins: {} })
const pkg = JSON.parse(await project.read('package.json'))
pkg.devDependencies['@vue/cli-plugin-typescript'] = '*'
await project.write('package.json', JSON.stringify(pkg, null, 2))
2 changes: 1 addition & 1 deletion packages/@vue/cli/lib/GeneratorAPI.js
Original file line number Diff line number Diff line change
@@ -17,7 +17,7 @@ const mergeArrayWithDedupe = (a, b) => Array.from(new Set([...a, ...b]))
function pruneObject (obj) {
if (typeof obj === 'object') {
for (const k in obj) {
if (!obj.hasOwnProperty(k)) {
if (!Object.prototype.hasOwnProperty.call(obj, k)) {
continue
}

6 changes: 3 additions & 3 deletions packages/@vue/cli/lib/util/ProjectPackageManager.js
Original file line number Diff line number Diff line change
@@ -88,7 +88,7 @@ function stripVersion (packageName) {
// extract the package scope from the full package name
// the result includes the initial @ character
function extractPackageScope (packageName) {
const scopedNameRegExp = /^(@[^\/]+)\/.*$/
const scopedNameRegExp = /^(@[^/]+)\/.*$/
const result = packageName.match(scopedNameRegExp)

if (!result) {
@@ -222,8 +222,8 @@ class PackageManager {

const registry = await this.getRegistry(scope)
const registryWithoutProtocol = registry
.replace(/https?:/, '') // remove leading protocol
.replace(/([^/])$/, '$1/') // ensure ending with slash
.replace(/https?:/, '') // remove leading protocol
.replace(/([^/])$/, '$1/') // ensure ending with slash
const authTokenKey = `${registryWithoutProtocol}:_authToken`

return npmConfig[authTokenKey]
2 changes: 1 addition & 1 deletion packages/@vue/cli/lib/util/executeCommand.js
Original file line number Diff line number Diff line change
@@ -135,7 +135,7 @@ exports.executeCommand = function executeCommand (command, args, cwd) {

child.on('close', code => {
if (code !== 0) {
reject(`command failed: ${command} ${args.join(' ')}`)
reject(new Error(`command failed: ${command} ${args.join(' ')}`))
return
}
resolve()
2 changes: 1 addition & 1 deletion packages/@vue/cli/lib/util/loadPresetFromDir.js
Original file line number Diff line number Diff line change
@@ -12,7 +12,7 @@ module.exports = async function loadPresetFromDir (dir) {
// plugin so it will be invoked by the generator.
const hasGenerator = fs.existsSync(path.join(dir, 'generator.js')) || fs.existsSync(path.join(dir, 'generator/index.js'))
if (hasGenerator) {
(preset.plugins || (preset.plugins = {}))[dir.replace(/[\/]$/, '')] = {
(preset.plugins || (preset.plugins = {}))[dir.replace(/[/]$/, '')] = {
_isPreset: true,
prompts: true
}
2 changes: 1 addition & 1 deletion packages/@vue/cli/lib/util/sortObject.js
Original file line number Diff line number Diff line change
@@ -4,7 +4,7 @@ module.exports = function sortObject (obj, keyOrder, dontSortByUnicode) {

if (keyOrder) {
keyOrder.forEach(key => {
if (obj.hasOwnProperty(key)) {
if (Object.prototype.hasOwnProperty.call(obj, key)) {
res[key] = obj[key]
delete obj[key]
}