Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
369 views
in Technique[技术] by (71.8m points)

javascript - Eslint:如何在Node.js中禁用“意外的控制台语句”?(Eslint: How to disable “unexpected console statement” in Node.js?)

I'm using eslint with Sublime Text 3 and I am writing gulpfile.js .

(我将eslint与Sublime Text 3结合使用,并且正在编写gulpfile.js 。)

/*eslint-env node*/
var gulp = require('gulp');

gulp.task('default', function(){
    console.log('default task');
});

But eslint keeps showing error : "Error: Unexpected console statement. (no-console)"

(但是eslint不断显示错误:“错误:意外的控制台语句。(无控制台)”)

陪同错误

I found official document here , but I still don't know how to disable it.

(我在这里找到了官方文档 ,但是我仍然不知道如何禁用它。)

/*eslint-env node*/
var gulp = require('gulp');

/*eslint no-console: 2*/
gulp.task('default', function(){
    console.log('default task');
});

doesn't work, either.

(也不起作用。)

My Sublime Text 3 plugins: SublimeLinter and SublimeLinter-contrib-eslint.

(我的Sublime Text 3插件:SublimeLinter和SublimeLinter-contrib-eslint。)

Here's my .eslintrc.js file:

(这是我的.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"
};
  ask by Jean Y.C. Yang translate from so

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

Create a .eslintrc.js in the directory of your file, and put the following contents in it:

(在文件目录中创建一个.eslintrc.js,并将以下内容放入其中:)

module.exports = {
    rules: {
        'no-console': 'off',
    },
};

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...