Eslint : Node.js에서“예기치 않은 콘솔 명령문”을 비활성화하는 방법은 무엇입니까?
Sublime Text 3과 함께 eslint를 사용하고 gulpfile.js
있습니다.
/*eslint-env node*/
var gulp = require('gulp');
gulp.task('default', function(){
console.log('default task');
});
그러나 eslint는 계속 오류 : "오류 : 예기치 않은 콘솔 설명. (콘솔 없음)"
공식 문서를 여기 에서 찾았 지만 여전히 비활성화하는 방법을 모르겠습니다.
/*eslint-env node*/
var gulp = require('gulp');
/*eslint no-console: 2*/
gulp.task('default', function(){
console.log('default task');
});
작동하지 않습니다.
My Sublime Text 3 플러그인 : SublimeLinter 및 SublimeLinter-contrib-eslint.
내 .eslintrc.js
파일은 다음과 같습니다 .
module.exports = {
"rules": {
"no-console":0,
"indent": [
2,
"tab"
],
"quotes": [
2,
"single"
],
"linebreak-style": [
2,
"unix"
],
"semi": [
2,
"always"
]
},
"env": {
"browser": true,
"node": true
},
"extends": "eslint:recommended"
};
파일 디렉토리에 .eslintrc.js를 작성하고 다음 내용을 파일에 넣으십시오.
module.exports = {
rules: {
'no-console': 'off',
},
};
eslint 구성 파일을 업데이트하여이 문제를 영구적으로 해결해야합니다. 그렇지 않으면 아래처럼 콘솔에 대한 eslint 검사를 일시적으로 활성화 또는 비활성화 할 수 있습니다
/* eslint-disable no-console */
console.log(someThing);
/* eslint-enable no-console */
For vue-cli 3 open package.json
and under section eslintConfig
put no-console
under rules
and restart dev server (npm run serve
or yarn serve
)
...
"eslintConfig": {
...
"rules": {
"no-console": "off"
},
...
A nicer option is to make the display of console.log and debugger statements conditional based on the node environment.
rules: {
// allow console and debugger in development
'no-console': process.env.NODE_ENV === 'production' ? 2 : 0,
'no-debugger': process.env.NODE_ENV === 'production' ? 2 : 0,
},
If you install eslint under your local project, you should have a directory /node_modules/eslint/conf/ and under that directory a file eslint.json. You could edit the file and modify "no-console" entry with the value "off" (although 0 value is supported too):
"rules": {
"no-alert": "off",
"no-array-constructor": "off",
"no-bitwise": "off",
"no-caller": "off",
"no-case-declarations": "error",
"no-catch-shadow": "off",
"no-class-assign": "error",
"no-cond-assign": "error",
"no-confusing-arrow": "off",
"no-console": "off",
....
I hope this "configuration" could help you.
The following works with ESLint in VSCode if you want to disable the rule for just one line.
To disable the next line:
// eslint-disable-next-line no-console
console.log('hello world');
To disable the current line:
console.log('hello world'); // eslint-disable-line no-console
I'm using Ember.js which generates a file named .eslintrc.js
. Adding "no-console": 0
to the rules object did the job for me. The updated file looks like this:
module.exports = {
root: true,
parserOptions: {
ecmaVersion: 6,
sourceType: 'module'
},
extends: 'eslint:recommended',
env: {
browser: true
},
rules: {
"no-console": 0
}
};
If you just want to disable the rule once, you want to look at Exception's answer.
You can improve this by only disabling the rule for one line only:
... on the current line:
console.log(someThing); /* eslint-disable-line no-console */
... or on the next line:
/* eslint-disable-next-line no-console */
console.log(someThing);
in my vue
project i fixed this problem like this :
vim package.json
...
"rules": {
"no-console": "off"
},
...
ps : package.json is a configfile in the vue project dir, finally the content shown like this:
{
"name": "metadata-front",
"version": "0.1.0",
"private": true,
"scripts": {
"serve": "vue-cli-service serve",
"build": "vue-cli-service build",
"lint": "vue-cli-service lint"
},
"dependencies": {
"axios": "^0.18.0",
"vue": "^2.5.17",
"vue-router": "^3.0.2"
},
"devDependencies": {
"@vue/cli-plugin-babel": "^3.0.4",
"@vue/cli-plugin-eslint": "^3.0.4",
"@vue/cli-service": "^3.0.4",
"babel-eslint": "^10.0.1",
"eslint": "^5.8.0",
"eslint-plugin-vue": "^5.0.0-0",
"vue-template-compiler": "^2.5.17"
},
"eslintConfig": {
"root": true,
"env": {
"node": true
},
"extends": [
"plugin:vue/essential",
"eslint:recommended"
],
"rules": {
"no-console": "off"
},
"parserOptions": {
"parser": "babel-eslint"
}
},
"postcss": {
"plugins": {
"autoprefixer": {}
}
},
"browserslist": [
"> 1%",
"last 2 versions",
"not ie <= 8"
]
}
You should add one rule and add your env:
{
"rules": {
"no-console": "off"
},
"env": {
"browser": true
}
}
you can add other envs.
In package.json you will find an eslintConfig
line. Your 'rules' line can go in there like this:
"eslintConfig": {
...
"extends": [
"eslint:recommended"
],
"rules": {
"no-console": "off"
},
...
},
2018 October,
just do:
// tslint:disable-next-line:no-console
the anothers answer with
// eslint-disable-next-line no-console
does not work !
Putting this in the .eslintrc.js file that is at the project location worked for me
module.exports = {
rules: {
'no-console': 0
}
};
'Programing' 카테고리의 다른 글
ActiveRecord 객체가 New인지 확인 (0) | 2020.05.01 |
---|---|
WPF TextBox에서 모든 텍스트를 자동으로 선택하는 방법은 무엇입니까? (0) | 2020.05.01 |
NodeJS 모듈에서 상수를 어떻게 공유합니까? (0) | 2020.05.01 |
MongoDB에서 한 데이터베이스에서 다른 데이터베이스로 컬렉션을 복사하는 방법 (0) | 2020.05.01 |
데이터 프레임 문자열 열을 여러 열로 분할 (0) | 2020.05.01 |