我的项目中有简单的ejs文件。该项目运行良好。
我想使用eslint使用ejs插件检查我的文件。
我有错误:错误解析错误:文件第一行出现了意外的令牌。
我的.eslintrc.json文件:
{
"parser": "babel-eslint",
"plugins": [
"mocha",
"markdown",
"json",
"ejs"
],
"extends": "airbnb",
"rules": {
"linebreak-style": ["off", "unix"],
"semi": ["error", "never"]
},
"env": {
"node": true,
"mocha": true
}
}
我的package.json文件:
{
"name": "xxxxx",
"version": "0.0.0",
"private": true,
"scripts": {
"start": "node ./bin/www",
"test": "bash hooks/check.sh test",
"linter-js": "bash hooks/check.sh linter-js",
"linter-sh": "bash hooks/check.sh linter-sh",
"linter-yml": "bash hooks/check.sh linter-yml",
"coverage": "bash hooks/check.sh coverage",
"TF": "bash hooks/check.sh TF"
},
"pre-commit": [
"linter-js",
"linter-sh",
"linter-yml",
"TF"
],
"dependencies": {
"babel-eslint": "^10.0.1",
"chai": "^4.2.0",
"cookie-parser": "~1.4.3",
"debug": "~2.6.9",
"ejs": "~2.5.7",
"eslint-config-airbnb": "^17.1.0",
"eslint-config-airbnb-base": "^13.1.0",
"eslint-plugin-import": "^2.17.2",
"eslint-plugin-jsx-a11y": "^6.2.1",
"eslint-plugin-mocha": "^5.3.0",
"eslint-plugin-react": "^7.13.0",
"express": "~4.16.0",
"fs": "0.0.1-security",
"http-errors": "^1.6.3",
"https": "^1.0.0",
"mocha": "^6.1.4",
"morgan": "~1.9.0",
"pre-commit": "^1.2.2"
},
"devDependencies": {
"eslint": "^5.16.0",
"eslint-plugin-ejs": "0.0.2",
"eslint-plugin-json": "^1.4.0",
"eslint-plugin-markdown": "^1.0.0",
"yaml-lint": "^1.2.4"
}
}
我的error.ejs文件
<h1><%= message %></h1>
<h2><%= error.status %></h2>
<pre><%= error.stack %></pre>
[当我运行npx eslint views / error.ejs时,我得到了:
/Users/selim/Documents/Programmation/Univers/views/error.ejs
1:6 error Parsing error: Unexpected token
> 1 | <h1><%= message %></h1>
| ^
2 | <h2><%= error.status %></h2>
3 | <pre><%= error.stack %></pre>
4 |
✖ 1 problem (1 error, 0 warnings)
我在运行npx eslint --debug views / error.ejs时有更多信息:
eslint:cli CLI args: [ '--debug', 'views/error.ejs' ] +0ms
eslint:cli Running on files +4ms
eslint:glob-utils Creating list of files to process. +0ms
eslint:ignored-paths baseDir = "/Users/selim/Documents/Programmation/Univers" +0ms
eslint:ignored-paths addPatternRelativeToCwd:
eslint:ignored-paths original = "/node_modules/*"
eslint:ignored-paths cooked = "/node_modules/*" +1ms
eslint:ignored-paths addPatternRelativeToCwd:
eslint:ignored-paths original = "/bower_components/*"
eslint:ignored-paths cooked = "/bower_components/*" +0ms
eslint:ignored-paths addPatternRelativeToCwd:
eslint:ignored-paths original = ".*"
eslint:ignored-paths cooked = ".*" +1ms
eslint:ignored-paths addPatternRelativeToCwd:
eslint:ignored-paths original = "!../"
eslint:ignored-paths cooked = "!../" +0ms
eslint:ignored-paths Looking for ignore file in /Users/selim/Documents/Programmation/Univers +0ms
eslint:ignored-paths Could not find ignore file in cwd +0ms
eslint:ignored-paths contains: +1ms
eslint:ignored-paths target = "/Users/selim/Documents/Programmation/Univers/views/error.ejs" +0ms
eslint:ignored-paths result = false +0ms
eslint:ignored-paths contains: +1ms
eslint:ignored-paths target = "/Users/selim/Documents/Programmation/Univers/views/error.ejs" +0ms
eslint:ignored-paths result = false +0ms
eslint:cli-engine Processing /Users/selim/Documents/Programmation/Univers/views/error.ejs +0ms
eslint:cli-engine Linting /Users/selim/Documents/Programmation/Univers/views/error.ejs +1ms
eslint:config Constructing config file hierarchy for /Users/selim/Documents/Programmation/Univers/views +0ms
eslint:config Using .eslintrc and package.json files +0ms
eslint:config Loading /Users/selim/Documents/Programmation/Univers/.eslintrc.json +1ms
eslint:config-file Loading JSON config file: /Users/selim/Documents/Programmation/Univers/.eslintrc.json +0ms
eslint:plugins Loaded plugin mocha ([email protected]) (from /Users/selim/Documents/Programmation/Univers/node_modules/eslint-plugin-mocha/index.js) +0ms
eslint:plugins Loaded plugin markdown ([email protected]) (from /Users/selim/Documents/Programmation/Univers/node_modules/eslint-plugin-markdown/index.js) +32ms
eslint:plugins Loaded plugin json ([email protected]) (from /Users/selim/Documents/Programmation/Univers/node_modules/eslint-plugin-json/lib/index.js) +25ms
eslint:plugins Loaded plugin ejs ([email protected]) (from /Users/selim/Documents/Programmation/Univers/node_modules/eslint-plugin-ejs/lib/index.js) +1ms
eslint:config-file Loading airbnb +164ms
eslint:config-file Attempting to resolve eslint-config-airbnb +0ms
eslint:config-file Loading JS config file: /Users/selim/Documents/Programmation/Univers/node_modules/eslint-config-airbnb/index.js +1ms
eslint:config-file Loading /Users/selim/Documents/Programmation/Univers/node_modules/eslint-config-airbnb/rules/react-a11y.js +2ms
eslint:config-file Loading JS config file: /Users/selim/Documents/Programmation/Univers/node_modules/eslint-config-airbnb/rules/react-a11y.js +0ms
eslint:plugins Loaded plugin jsx-a11y ([email protected]) (from /Users/selim/Documents/Programmation/Univers/node_modules/eslint-plugin-jsx-a11y/lib/index.js) +148ms
eslint:plugins Loaded plugin react ([email protected]) (from /Users/selim/Documents/Programmation/Univers/node_modules/eslint-plugin-react/index.js) +48ms
eslint:config-file Loading /Users/selim/Documents/Programmation/Univers/node_modules/eslint-config-airbnb/rules/react.js +199ms
eslint:config-file Loading JS config file: /Users/selim/Documents/Programmation/Univers/node_modules/eslint-config-airbnb/rules/react.js +0ms
eslint:config-file Loading /Users/selim/Documents/Programmation/Univers/node_modules/eslint-config-airbnb-base/rules/strict.js +39ms
eslint:config-file Loading JS config file: /Users/selim/Documents/Programmation/Univers/node_modules/eslint-config-airbnb-base/rules/strict.js +0ms
eslint:config-file Loading /Users/selim/Documents/Programmation/Univers/node_modules/eslint-config-airbnb-base/index.js +1ms
eslint:config-file Loading JS config file: /Users/selim/Documents/Programmation/Univers/node_modules/eslint-config-airbnb-base/index.js +0ms
eslint:config-file Loading /Users/selim/Documents/Programmation/Univers/node_modules/eslint-config-airbnb-base/rules/imports.js +1ms
eslint:config-file Loading JS config file: /Users/selim/Documents/Programmation/Univers/node_modules/eslint-config-airbnb-base/rules/imports.js +0ms
eslint:plugins Loaded plugin import ([email protected]) (from /Users/selim/Documents/Programmation/Univers/node_modules/eslint-plugin-import/lib/index.js) +138ms
eslint:config-file Loading /Users/selim/Documents/Programmation/Univers/node_modules/eslint-config-airbnb-base/rules/es6.js +86ms
eslint:config-file Loading JS config file: /Users/selim/Documents/Programmation/Univers/node_modules/eslint-config-airbnb-base/rules/es6.js +1ms
eslint:config-file Loading /Users/selim/Documents/Programmation/Univers/node_modules/eslint-config-airbnb-base/rules/variables.js +14ms
eslint:config-file Loading JS config file: /Users/selim/Documents/Programmation/Univers/node_modules/eslint-config-airbnb-base/rules/variables.js +0ms
eslint:config-file Loading /Users/selim/Documents/Programmation/Univers/node_modules/eslint-config-airbnb-base/rules/style.js +7ms
eslint:config-file Loading JS config file: /Users/selim/Documents/Programmation/Univers/node_modules/eslint-config-airbnb-base/rules/style.js +0ms
eslint:config-file Loading /Users/selim/Documents/Programmation/Univers/node_modules/eslint-config-airbnb-base/rules/node.js +99ms
eslint:config-file Loading JS config file: /Users/selim/Documents/Programmation/Univers/node_modules/eslint-config-airbnb-base/rules/node.js +0ms
eslint:config-file Loading /Users/selim/Documents/Programmation/Univers/node_modules/eslint-config-airbnb-base/rules/errors.js +1ms
eslint:config-file Loading JS config file: /Users/selim/Documents/Programmation/Univers/node_modules/eslint-config-airbnb-base/rules/errors.js +0ms
eslint:config-file Loading /Users/selim/Documents/Programmation/Univers/node_modules/eslint-config-airbnb-base/rules/best-practices.js +6ms
eslint:config-file Loading JS config file: /Users/selim/Documents/Programmation/Univers/node_modules/eslint-config-airbnb-base/rules/best-practices.js +0ms
eslint:config Using /Users/selim/Documents/Programmation/Univers/.eslintrc.json +638ms
eslint:config-ops Using config from partial cache +0ms
eslint:config-ops Apply environment settings to config +1ms
eslint:config-ops Creating config for environment node +0ms
eslint:config-ops Creating config for environment es6 +0ms
eslint:config-ops Creating config for environment mocha +0ms
eslint:linter Linting code for /Users/selim/Documents/Programmation/Univers/views/error.ejs (pass 1) +0ms
eslint:linter Generating fixed text for /Users/selim/Documents/Programmation/Univers/views/error.ejs (pass 1) +113ms
eslint:source-code-fixer Applying fixes +0ms
eslint:source-code-fixer shouldFix parameter was false, not attempting fixes +0ms
eslint:cli-engine Linting complete in: 763ms +757ms
/Users/selim/Documents/Programmation/Univers/views/error.ejs
1:6 error Parsing error: Unexpected token
> 1 | <h1><%= message %></h1>
| ^
2 | <h2><%= error.status %></h2>
3 | <pre><%= error.stack %></pre>
4 |
✖ 1 problem (1 error, 0 warnings)
我不知道为什么会有这个错误。我的代码似乎正确。
同样的问题还在寻找,如果找到解决方案,请更新