Jea*_*ang 229 javascript node.js sublimetext3 eslint sublime-text-plugin
我正在使用与Sublime Text 3的eslint,我正在写作gulpfile.js.
/*eslint-env node*/
var gulp = require('gulp');
gulp.task('default', function(){
console.log('default task');
});
Run Code Online (Sandbox Code Playgroud)
但是eslint一直显示错误:"错误:意外的控制台声明.(无控制台)"

/*eslint-env node*/
var gulp = require('gulp');
/*eslint no-console: 2*/
gulp.task('default', function(){
console.log('default task');
});
Run Code Online (Sandbox Code Playgroud)
也行不通.
我的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"
};
Run Code Online (Sandbox Code Playgroud)
mar*_*are 395
在文件的目录中创建.eslintrc.js,并在其中放入以下内容:
module.exports = {
rules: {
'no-console': 'off',
},
};
Run Code Online (Sandbox Code Playgroud)
Exc*_*ion 118
您应该更新eslint配置文件以永久修复此问题.否则,您可以暂时启用或禁用以下控制台的eslint检查
/* eslint-disable no-console */
console.log(someThing);
/* eslint-enable no-console */
Run Code Online (Sandbox Code Playgroud)
Gio*_*osK 85
对于VUE-CLI 3开放package.json和第eslintConfig穿上no-console下rules并重新启动开发服务器(npm run serve或yarn serve)
...
"eslintConfig": {
...
"rules": {
"no-console": "off"
},
...
Run Code Online (Sandbox Code Playgroud)
Fra*_*pin 30
一个更好的选择是根据节点环境使console.log和调试器语句的显示成为条件.
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,
},
Run Code Online (Sandbox Code Playgroud)
小智 13
如果在本地项目下安装eslint,则应该在目录/ node_modules/eslint/conf /下有一个文件eslint.json.您可以编辑文件并使用值"off"修改"no-console"条目(尽管也支持0值):
"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",
....
Run Code Online (Sandbox Code Playgroud)
我希望这个"配置"可以帮到你.
bin*_*ici 12
如果要仅禁用一行规则,以下内容适用于VSCode中的ESLint.
要禁用下一行:
// eslint-disable-next-line no-console
console.log('hello world');
Run Code Online (Sandbox Code Playgroud)
要禁用当前行:
console.log('hello world'); // eslint-disable-line no-console
Run Code Online (Sandbox Code Playgroud)
Ben*_*eer 10
我正在使用Ember.js生成一个名为的文件.eslintrc.js.添加"no-console": 0到规则对象为我做了工作.更新的文件如下所示:
module.exports = {
root: true,
parserOptions: {
ecmaVersion: 6,
sourceType: 'module'
},
extends: 'eslint:recommended',
env: {
browser: true
},
rules: {
"no-console": 0
}
};
Run Code Online (Sandbox Code Playgroud)
Koe*_*oen 10
如果您只想禁用一次规则,则需要查看Exception的答案.
您可以通过仅禁用一行规则来改进此问题:
...在当前行:
console.log(someThing); /* eslint-disable-line no-console */
Run Code Online (Sandbox Code Playgroud)
......或在下一行:
/* eslint-disable-next-line no-console */
console.log(someThing);
Run Code Online (Sandbox Code Playgroud)
在我的vue项目中,我解决了以下问题:
vim package.json
...
"rules": {
"no-console": "off"
},
...
Run Code Online (Sandbox Code Playgroud)
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"
]
}
Run Code Online (Sandbox Code Playgroud)
如果根据文档配置 package.json 后仍然遇到问题(如果您选择使用 package.json 来跟踪而不是单独的配置文件):
"rules": {
"no-console": "off"
},
Run Code Online (Sandbox Code Playgroud)
它仍然不适合您,不要忘记您需要返回命令行并再次执行 npm install。:)
或者,您可以允许,而不是关闭“无控制台”。在.eslintrc.js文件中放入
rules: {
"no-console": [
"warn",
{ "allow": ["clear", "info", "error", "dir", "trace", "log"] }
]
}
Run Code Online (Sandbox Code Playgroud)
这将允许你这样做console.log,并console.clear没有引发错误等。
在package.json中,您将找到eslintConfig一行。您的“规则”行可以像这样进入:
"eslintConfig": {
...
"extends": [
"eslint:recommended"
],
"rules": {
"no-console": "off"
},
...
},
Run Code Online (Sandbox Code Playgroud)
2018 年 10 月,
做就是了:
// tslint:disable-next-line:no-console
Run Code Online (Sandbox Code Playgroud)
别人回答
// eslint-disable-next-line no-console
Run Code Online (Sandbox Code Playgroud)
不工作!
| 归档时间: |
|
| 查看次数: |
165384 次 |
| 最近记录: |