JSLint和ESLint问题(括号)

时间:2019-03-09 06:03:01

标签: node.js json eslint jslint nunjucks

我正在为我正在做的一个小项目创建一个模拟网站。我正在使用nunjucks执行一些任务。尝试创建一个以后可以运行的.js文件时,出现错误。

我看了网上,并尝试了所有解决方案。我无法让他们工作。

我的代码:

const nunjucks = require('nunjucks');
const fs = require('fs');  // The file system module

let files = ["index.html", "About.html", "Membership.html", "Fighting%20Kites.html"];
let srcDir = "./content/";
let outDir = "./output/";

// Tells nunjucks where to look for templates and set any options
nunjucks.configure('views', { autoescape: true });

for (let fname of files) {
let contents = fs.readFileSync(srcDir + fname);
let outString = nunjucks.render('base.njk', {mainContent: contents});
fs.writeFileSync(outDir + fname, outString);
console.log(`Wrote file: ${fname}`);
}

我的错误消息:

JSLint (2)
1   Expected an identifier and instead saw 'const'. const nunjucks = require('nunjucks');
1   Stopping. (10% scanned).    const nunjucks = require('nunjucks');

ESLint (1)
1   ERROR: Parsing error: The keyword 'const' is reserved   const nunjucks = require('nunjucks');

我不知道该如何解决。任何想法都有帮助。

1 个答案:

答案 0 :(得分:1)

const是ES6 JavaScript功能。尝试为Eslint启用ES6语法:

{
    "parserOptions": {
        "ecmaVersion": 6,
        "sourceType": "module",
    }
}