zoukankan      html  css  js  c++  java
  • 总结前端开发模式和规范 1、jshint 详解

    jshint是一个javaScript语法和风格的检查工具,但检查不出逻辑问题。

    安装
    一、在sublime text 中使用jshint插件步骤:
    (注:在为Sublime Text编辑器安装Sublime-JSHint插件之前,要首先确保安装了node.js)

    方法1:
    1 Ctrl+Shift+P 呼出Sublime命令面板
    2 键入install,并选择Package Control:Install Package
    3 键入js gutter,并选择JSHint Gutter

    方法2:
    1 获取Sublime Text,可通过git命令。

     git clone https://github.com/victorporof/Sublime-JSHint.git
    

    2 打开 Sublime Text Package 文件夹。Preferences -> Browse Packages。
    3 将步骤1中获取到的 Sublime-JSHint 文件夹移到 Packages 文件夹中。
    4 重启 Sublime Text。

    Sublime-JSHint使用
    方法1:由菜单 Tools -> Command Palette(或快捷键 Ctrl+Shift+P)打开命令面板。键入 jshint 并选择 JSHint。
    方法2:打开一 js 文件,并打开控制台(View -> Show Console),在控制台中键入 view.run_command("jshint")。
    方法3:Ctrl+Shift+J(或者Mac使用Cmd+Shift+J)
    方法4:右键选择JSHint

    设置

      "lint_on_edit": false,
    
      // Configurable duration before re-linting.
      "lint_on_edit_timeout": 5,
    
      // Automatically lint when a file is loaded.
      "lint_on_load": false,
    
      // Automatically lint when a file is saved.
      "lint_on_save": false,
    
      // Highlight problematic regions when selected.
      "highlight_selected_regions": false,
    
      // Log the settings passed to JSHint from `.jshintrc`.
      "print_diagnostics": true
    

    配置选项

    "strict": true, //严格模式 参考文章(http://www.ruanyifeng.com/blog/2013/01/javascript_strict_mode.html)
    "asi": true, //允许省略分号(写上这条,规避检查出很多警告  可以去掉)
    "bitwise": true, //禁止使用位运算符,比如经常把&&写错& 规避此错误
    "noarg": true, //禁止使用.caller 和 .callee (ECMS5已经禁用了此 可以去掉)
    "eqeqeq": true, //禁止使用== 和 !=  强制使用=== 和 !==
    "undef": true, //禁止使用不在全局变量列表中的未定义变量
    "curly": true, //循环或者条件语句必须使用花括号包住
    "devel": true, //定义用于调试的全局变量:console,alert 
    "jquery": true, //定义全局暴露的jQuery库 (可以去掉)
    "browser": true, //暴露浏览器属性的全局变量 如window document
    "evil": true, //禁止使用eval (可以去掉)
    "quotemark":true (商榷)
    "globals": {"$":true,"require":true,"FastClick":true,"Swiper"},
    

    编辑器 VS Gulp_jshint
    1 个人偏向于在编辑器中使用jshint,这样不用在每个项目都配置,同时也能约束项目之外的编辑。
    2 在编辑器中使用jshint 比在Gulp_jshint 的更实时,更清晰。jshint有错误,会在每一行有提示。而后者会在命令窗口提示,不方便。
    3 Gulp_jshint 还需要进一步探查。

    项目中一些问题
    无法识别的一些问题:

    1 //= require chartjs/chart.core (解决掉了)
    2 封闭空间上面的(未解决);
    3 引入插件的实例化:comRadar = new Chart(ctx).Radar()(解决掉了);
    //配置参数
    "globals": {"$":true,"require":true,"FastClick":true,"Swiper"},
    4  var CardPopup = function(el, opts) {
            this.el = el;
            this.defaults = {};
            this.options = $.extend({}, this.defaults, opts);
        } (此处加封号)
       CardPopup.prototype = {
            init: function() {
                var me = this,
                    el = me.el;
                return me;
            },
        } (此处加封号)
        $.fn.CardPopup = function(opts) {
            var com;
        } (此处加封号)
    5 A && B  
    //要么写成 if(A) B
    //或者 /* jshint expr: true */
    6 jshint 中希望 A.B  而不希望A[B]
    7 /* jshint ignore:start */ 
    var optionTemplate = Hogan.compile('<ul class="items options clearfix count-{{count}}">
                                                {{#options}}
                                                <li class="item option {{#selected}}selected{{/selected}}">
                                                    <div class="pie">
                                                        <canvas class="canvas-outer" data-percent="{{value}}"></canvas>
                                                        <div class="num">{{value}}%</div>
                                                    </div>
                                                    <p class="text">{{text}}</p>
                                                </li>
                                                {{/options}}
                                            </ul>');
    /* jshint ignore:end */
    8  /*jshint scripturl:true*/  
    data.top[i].redirect_url = data.top[i].redirect_url || 'javascript:void(0);';
    9 $(subscribeData).each(function(index, element) {
        if (element == specialColumnId) {
           elSubscribe.removeClass('icon-jiadingyue').addClass('icon-yidingyue');
          }
       }) (是否加)
    10 
    /*jshint -W018 */
    if (!!elForm.find('[name="comment[parent_id]"]').val() == true) {
          isReplyComment = true;
        }


    作者:天外来人
    链接:https://www.jianshu.com/p/9c26c61da146
    來源:简书
    著作权归作者所有。商业转载请联系作者获得授权,非商业转载请注明出处。
  • 相关阅读:
    PS 如何制作眼泪效果
    PS 基础知识 什么是Adobe Bridge
    PS 抠图如何使用通道法处理头发
    PS 如何使用抽出滤镜抠人物的头发丝等细节
    PS 如何用PS制作GIF图像
    PS 如何制作柔和的边框
    PS 基础知识 如何绘制几何图形
    PS 基础知识 渐变编辑器如何使用
    PS 基础知识 CMYK全称是什么
    [Functional Programming] Daggy
  • 原文地址:https://www.cnblogs.com/xingfuboke/p/8133928.html
Copyright © 2011-2022 走看看