简体   繁体   English

来自Visual Studio的EsLint - 无法在javascript文件上使用静态道具

[英]EsLint from Visual Studio - Unable to use static props on javascript files

Node Modules: 节点模块:

  • EsLint 1.10.3 EsLint 1.10.3
  • Babel-EsLint 4.1.6 Babel-EsLint 4.1.6
  • Eslint-plugin-react 3.15.0 Eslint-plugin-react 3.15.0

Sample file being linted: 要点的示例文件:

class NotepadComponent extends React.Component {
    static displayName = 'NotepadComponent'

    static defaultProps = {
        activeTab: 'type'
    }
}

Under the command line I can lint and transpile using babel without any issues. 在命令行下,我可以使用babel进行lint和transpint而没有任何问题。 The problem is trying to lint from visual studio. 问题是尝试从视觉工作室lint。 I'm using the Web Analyzer plugin which internally uses esLint. 我正在使用内部使用esLint的Web Analyzer插件

This visual studio module defines a .eslintrc file under C:\\Users\\My-Username and I've gone ahead and updated this file, and the main folder for node_modules using this configuration: 这个visual studio模块在C:\\Users\\My-Username下定义了一个.eslintrc文件,我已经使用这个配置更新了这个文件和node_modules的主文件夹:

"parser": "babel-eslint",
"ecmaFeatures": {
    "jsx": true,
    "classes":  true
    },
    "plugins": [
        "react"
    ],
    "env": {
        "browser": true,
        "node": true,
        "es6": true,
        "jquery":  true
    },

But I still get the "JSX Parser: Unexpected Token =" error: 但我仍然得到“JSX Parser:Unexpected Token =”错误:

Any ideas on getting Web Analyzer to behave the same way the command-line tool does? 有关让Web Analyzer的行为与命令行工具相同的想法吗?

Visual Studio Linting错误

Actually in Es6 for the defaultProps you have to set it outside the class, example: 实际上在Es6中,defaultProps你必须在类外面设置它,例如:

class NotepadComponent extends React.Component {
  constructor(props){
    super(props);
  }
}
NotepadComponent.defaultProps ={
                               activeTab:'type'
                               }
NotepadComponent.displayName = 'NotepadComponent'

Im not sure if it's that are you looking for, but maybe this help you 我不确定你是否正在寻找,但也许这对你有所帮助

I had a same kind of a problem in combination with TSLint and Web Analyzer. 与TSLint和Web Analyzer结合使用时遇到了同样的问题。 It turns out Web Analyzer uses its own node_modules installation in C:\\Users\\[User]\\AppData\\Local\\Temp\\WebAnalyzer1.7.75. 事实证明,Web Analyzer在C:\\ Users \\ [User] \\ AppData \\ Local \\ Temp \\ WebAnalyzer1.7.75中使用自己的node_modules安装。 There you find also a nodeJS server(.js) that communicates the lint results to Visual Studio. 在那里你还发现了一个nodeJS服务器(.js),它将lint结果传递给Visual Studio。 I was able to adapt this server to get more error feedback in Visual Studio. 我能够调整此服务器以在Visual Studio中获得更多错误反馈。 This feedback told me that I should install missing npm packages in C:\\Users\\[User]\\AppData\\Local\\Temp\\WebAnalyzer1.7.75. 这个反馈告诉我,我应该在C:\\ Users \\ [User] \\ AppData \\ Local \\ Temp \\ WebAnalyzer1.7.75中安装缺少的npm软件包。 and C:\\Program Files (x86)\\Microsoft Visual Studio 14.0\\Common7\\IDE. 和C:\\ Program Files(x86)\\ Microsoft Visual Studio 14.0 \\ Common7 \\ IDE。 Maybe you can do the same for ESLint. 也许你可以为ESLint做同样的事情。 See also WebEssentials tslint custom rules 另请参阅WebEssentials tslint自定义规则

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM