想将Eslint,React和Cypress与essint cypress preprossor一起使用
package.json看起来像这样
{
"name": "react-hello-world",
"version": "1.0.0",
"description": "React Hello World",
"main": "index.js",
"scripts": {
"start": "react-scripts start",
"build": "react-scripts build",
"test": "react-scripts test --env=jsdom",
"eject": "react-scripts eject",
"cypress:open": "cypress open",
"cypress:run": "cypress run",
"eslint": "eslint"
},
"author": "CodeMix",
"license": "ISC",
"dependencies": {
"react": "^16.2.0",
"react-dom": "^16.2.0",
"react-scripts": "^1.1.1"
},
"devDependencies": {
"cypress": "^3.1.0",
"cypress-eslint-preprocessor": "^1.2.1",
"eslint": "^5.6.0",
"eslint-config-standard": "^12.0.0",
"eslint-plugin-cypress": "^2.0.1",
"eslint-plugin-import": "^2.14.0",
"eslint-plugin-node": "^7.0.1",
"eslint-plugin-promise": "^4.0.1",
"eslint-plugin-react": "^7.11.1",
"eslint-plugin-standard": "^4.0.0"
}
}
.eslintrc.json看起来像这样
{
"extends": [
"standard",
"eslint:recommended",
"plugin:react/recommended",
"plugin:import/errors",
"plugin:import/warnings",
"plugin:node/recommended",
"plugin:promise/recommended"
],
"plugins": [
"react",
"cypress",
"import",
"node",
"promise"
],
"rules": {
"react/jsx-uses-react": "error",
"react/jsx-uses-vars": "error"
},
"env": {
"cypress/globals": true
},
"settings": {
"react": {
"createClass": "createReactClass",
"pragma": "React",
"version": "16.5.2"
},
"propWrapperFunctions": ["forbidExtraProps"]
},
"parserOptions": {
"ecmaVersion": 9,
"ecmaFeatures": {
"jsx": true
}
}
}
cypress插件看起来像这样:
// cypress/plugins/index.js
const cypressEslint = require('cypress-eslint-preprocessor');
module.exports = (on) => {
on('file:preprocessor', cypressEslint());
}
执行npm run cypress:run会给出错误:
运行:examples / actions.spec.js ...(第1个,共19个)
错误 /Users/stein/Development/TimeLogging/TimeLogging/cypress/integration/examples/actions.spec.js
cypress / integration / examples / actions.spec.js未定义:未定义 错误分析错误:无法读取未定义的属性'ecmaFeatures' 空
如何解决此错误?