简体   繁体   English

.js文件的ESLint错误

[英]ESLint errors with .js file

Update I removed the env code and I'm still receiving 6 ESLint errors with my code and I'm not sure why. 更新我删除了env代码,我仍然接受我的代码6个ESLint错误,我不知道为什么。

Here are the errors: 错误如下:

ERROR: 'window' is not defined. 错误:未定义“窗口”。 [no-undef] if ($(window).width() <= 640) { [no-undef] if($(window).width()<= 640){

ERROR: 'initMap' is defined but never used. 错误:已定义“ initMap”,但从未使用过。 [no-unused-vars] function initMap() { [no-unused-vars]函数initMap(){

ERROR: 'google' is not defined. 错误:未定义“ google”。 [no-undef] var map = new google.maps.Map(document.getElementById("map"), { [no-undef] var map = new google.maps.Map(document.getElementById(“ map”),{

ERROR: 'document' is not defined. 错误:未定义“文档”。 [no-undef] var map = new google.maps.Map(document.getElementById("map"), { [no-undef] var map = new google.maps.Map(document.getElementById(“ map”),{

ERROR: 'marker' is assigned a value but never used. 错误:“标记”已分配一个值,但从未使用。 [no-unused-vars] var marker = new google.maps.Marker({ [no-unused-vars] var marker = new google.maps.Marker({

ERROR: 'google' is not defined. 错误:未定义“ google”。 [no-undef] var marker = new google.maps.Marker({ [no-undef] var marker = new google.maps.Marker({

Any help would be appreciated! 任何帮助,将不胜感激!

/*eslint-env jquery*/

if ($(window).width() <= 640) {
$(".cross").hide();
$(".menu").hide();
$(".hamburger").show();

$(".hamburger").on("click", function () {
    $(".menu").slideToggle("slow");
    $(".hamburger").hide();
    $(".cross").show();
});

$(".cross").on("click", function () {
    $(".menu").slideToggle("slow");
    $(".cross").hide();
    $(".hamburger").show();
});
}

function initMap() {
var pip = {
    lat: 22.421645,
    lng: -98.731555
};
var map = new google.maps.Map(document.getElementById("map"), {
    zoom: 13,
    center: pip,
});
var marker = new google.maps.Marker({
    position: pip,
    map: map
});
}

The code you try to validate has a syntax error. 您尝试验证的代码存在语法错误。 This part: 这部分:

"env": {
"browser": true,
"node": true,
"jasmine": true    
},

...is either extraneous, or you don't show the whole snippet. ...或者是无关紧要的,或者您没有显示整个摘要。

If "env" is meant to be a variable, I think you need something like this: 如果“ env”是一个变量,我认为您需要这样的东西:

env = {
    "browser": true,
    "node": true,
    "jasmine": true
};

Proper indentation throughout would make this a lot easier to read 适当的缩进将使其更容易阅读

As Drew stated above, if env is a variable, you'll need an equals sign, not a colon. 如上文Drew所述,如果env是变量,则需要等号而不是冒号。 In addition, you'll want to declare the type. 另外,您需要声明类型。

const env = {
    "browser": true,
    "node": true,
    "jasmine": true
};

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

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