JSLint混合空格和制表符错误 [英] JSLint mixed spaces and tabs error

查看:96
本文介绍了JSLint混合空格和制表符错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我通过JSLint运行了以下内容:

I have run the following through JSLint:

$(document).ready(function() {

    /*
        Add paragraph on page load
    */

    // Get all header elements
    var header = document.getElementsByTagName('h1'),
        parent,
        newP,
        text;

    // Loop through the elements
    for (var i=0, m = header.length; i < m; i++) {
        parent = header[i].parentNode;
        newP = document.createElement("p");
        text = document.createTextNode('This paragraph was inserted with JavaScript!');
        newP.appendChild(text);
        // Insert the new P element after the header element in its parent node
        parent.insertBefore(newP, header[i].nextSibling);   
    }

    // so much easier with jQuery!
    //$('.section > h1').after('<p>I am a new paragraph &amp; I have been added to the page with javascript!</p>');

    /*
        Toggle show/hide
    */

    // display show/hide link - hidden by default if JS disabled as functionality is not available
    $('#content > .section > h2 > a').removeClass('hide');

    // hide What's new on page load - all content will be available if JS disabled  
    $('#content > .section > ul').addClass('hide');

    // show/hide content on click event
    $('#content > .section > h2 > a').live('click',function() {

        $('#content > .section > ul').toggle();

        return false;

    });

    /*
        JSON
    */

    var $jsonURL = 'scripts/response.json';

    $.ajax({
        type: 'GET',
        url: $jsonURL,
        dataType: "json",
        success: function(data){

            $.each(data.data, function(i, data){

                var $html = '';

                var $string = '';

                if (data.type == 'comment') {
                    $string = 'file';
                } else {
                    $string = 'workspace';
                }

                $html += '<li class="' + data.type + '">';

                $html += '<strong>New ' + data.type + '</strong> was added to the ' + $string + ' ';

                $html += '<a href="' + data.target + '">' + data.target + '</a> ';

                $html += '<a href="' + data.workspace + '">' + data.workspace + '</a>';

                $html += ' by <a href="#">' + data.user + '</a>'; 

                $html += '</li>';   

                $('#content > .section > ul').append($html);    

            });

        },
        error:function (xhr, ajaxOptions, thrownError){
            alert(xhr.status);
            alert(thrownError);
        }           
    }); 

});

我收到此错误:

Error:

Problem at line 89 character 4: Mixed spaces and tabs.

}

Implied global: $ 1,31,34,37,39,51,57,81, document 1,8,16,17, alert 87,88

不确定如何解决?

推荐答案

当您的缩进使用空格和制表符的组合时会发生此错误,例如 {SPACE} {SPACE} {TAB} {SPACE} {TAB} {SPACE} {TAB} 。我不确定为什么这是一个错误,而不是一个警告,但解决方案是重新访问该行,并确保你只使用空格或标签。

This error occurs when your indentation uses a combination of both spaces and tabs, for example, {SPACE}{SPACE}{TAB}{SPACE} or {TAB}{SPACE}{TAB}. I'm not really sure why it's an error and not a warning, but the solution is to revisit the line and make sure you only use spaces OR tabs.

问题使用混合选项卡和空格,在不同的应用程序中查看文件时,您可能会遇到缩进问题。例如,一个用户可能将选项卡配置为等于两个空格,另一个用户可以打开第一个用户的文件并查看不均匀的缩进,因为两个空格加一个选项卡等于6个空格而不是第一个应用程序中的4个空格。使用其中一个确保代码的可读性更好。

The problem with mixing tabs and spaces is you could run into indentation issues when the file is viewed in a different application. For instance, one user may have tabs configured to equal two spaces, another could open the first user's file and see uneven indentation because two spaces plus one tab equals 6 spaces as opposed to 4 in the first's app. Using one or the other ensures better readability of your code.

有趣的是,Stack Overflow将标签规范化为4个空格,因此将代码从此处复制并粘贴回JSLint修复程序问题。

Interestingly enough, Stack Overflow normalizes tabs into 4 spaces, so copying and pasting your code from here back into JSLint fixes the problem.

这篇关于JSLint混合空格和制表符错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆