ビジュアルコードでeslintを使用してjsファイルをフォーマットしていますが、実行するたびにエラーが発生します。実行するためのコマンドラインは次のとおりですnode ./node_modules/eslint/bin/eslint -- src --fix
エラーメッセージ
E:\PATH\src\reducers\roote-reducer.js
1:8 error There should be no space after '{' object-curly-spacing
1:26 error There should be no space before '}' object-curly-spacing
6:1 error Expected indentation of 1 tab but found 2 spaces indent
7:1 error Expected indentation of 1 tab but found 2 spaces indent
8:4 error Newline required at end of file but not found eol-last
E:\PATH\src\reducers\schedule-reducer.js
1:8 error There should be no space after '{' object-curly-spacing
1:22 error There should be no space before '}' object-curly-spacing
4:1 error Expected indentation of 1 tab but found 4 spaces indent
7:24 error Missing space before function parentheses space-before-function-paren
7:54 error Missing space before opening brace space-before-blocks
8:1 error Expected indentation of 1 tab but found 4 spaces indent
9:1 error Expected indentation of 1 tab but found 4 spaces indent
E:\PATH\src\register-service-worker.js
12:1 error Expected indentation of 1 tab but found 2 spaces indent
17:1 error Expected indentation of 5 tabs but found 6 spaces indent
17:7 error Use regex shorthands to improve readability Unicorn/regex-shorthand
22:1 error Expected indentation of 1 tab but found 2 spaces indent
✖ 309 problems (309 errors, 0 warnings)
309 errors, 0 warnings potentially fixable with the `--fix` option.
どうすれば自動的に修正できますか?
--fix
オプションを使用するには、eslintを直接実行する必要があります。
これを試して
./node_modules/.bin/eslint src --fix
形式は次のとおりです。
./node_modules/.bin/eslint --fix path/to/file.js
詳細については、 このスレッド (およびaravind1078の回答)を参照してください。
しなかった場合
extend(config, ctx) {
// Run ESLint on save
if (ctx.isDev && ctx.isClient) {
config.module.rules.Push({
enforce: 'pre',
test: /\.(js|vue)$/,
loader: 'eslint-loader',
exclude: /(node_modules)/,
options: {
fix: true
}
})
}
}
You. You can use this on the first page
const colors = require('vuetify/es5/util/colors').default
const pkg = require('./package')
require('dotenv').config()
module.exports = {
mode: 'universal',
/*
** Headers of the page
*/
head: {
titleTemplate: '%s - ' + process.env.npm_package_name,
title: process.env.npm_package_name || '',
meta: [
{ charset: 'utf-8' },
{ name: 'viewport', content: 'width=device-width, initial-scale=1' },
{
hid: 'description',
name: 'description',
content: process.env.npm_package_description || ''
}
],
link: [{ rel: 'icon', type: 'image/x-icon', href: '/favicon.ico' }]
},
/*
** Customize the progress-bar color
*/
loading: { color: '#fff' },
/*
** Global CSS
*/
css: [],
/*
** Plugins to load before mounting the App
*/
plugins: [],
/*
** Nuxt.js dev-modules
*/
buildModules: [
// Doc: https://github.com/nuxt-community/eslint-module
'@nuxtjs/eslint-module',
'@nuxtjs/vuetify'
],
/*
** Nuxt.js modules
*/
modules: [
// Doc: https://axios.nuxtjs.org/usage
'@nuxtjs/axios',
'@nuxtjs/pwa',
// Doc: https://github.com/nuxt-community/dotenv-module
'@nuxtjs/dotenv'
],
/*
** Axios module configuration
** See https://axios.nuxtjs.org/options
*/
axios: {},
/*
** vuetify module configuration
** https://github.com/nuxt-community/vuetify-module
*/
/*
** Build configuration
*/
build: {
extend(config, ctx) {
// Run ESLint on save
if (ctx.isDev && ctx.isClient) {
config.module.rules.Push({
enforce: 'pre',
test: /\.(js|vue)$/,
loader: 'eslint-loader',
exclude: /(node_modules)/,
options: {
fix: true
}
})
}
}
}
}
実行したのと同じ問題が発生しました
eslint --fix fileName.extention