简体   繁体   English

使用jshint强制执行2个空格缩进

[英]enforce 2 space indentation with jshint

I have a .jshintrc file with this config: 我有一个使用此配置的.jshintrc文件:

{
  "indent": 2
}

And I have a js file that looks like this: 我有一个js文件,看起来像这样:

var hello = angular.module('hello', ['hello.controllers']);

angular.module('hello.controllers', []).
controller('MainCtrl', ['$scope', function ($scope) {

  'use strict';

  // hello msg
    var helloMsg = 'Some Awesome Things';
  $scope.helloMsg = helloMsg;
}]);

And when I run jshint on the file, no error is thrown. 当我在文件上运行jshint时,不会引发任何错误。

Notice that the line var helloMsg = 'Some Awesome Things'; 注意,行var helloMsg = 'Some Awesome Things'; is indented two extra spaces. 缩进两个额外的空格。

What do I need to do so that jshint throws an error on the above code? 我需要怎么做才能使jshint在上面的代码上引发错误?

Are you using version >= 2.5.0? 您是否正在使用版本> = 2.5.0? If so, seems they removed it: 如果是这样,似乎他们将其删除了:

indent no longer provides warnings about indentation levels 缩进不再提供有关缩进级别的警告

https://github.com/jshint/jshint/releases/tag/2.5.0 https://github.com/jshint/jshint/releases/tag/2.5.0

如何执行<div>标签来使用页面中的可用空间?</div><div id="text_translate"><p> 我正在开发一个示例网站来学习 CSS 和 HTML。 在页面顶部创建了水平导航栏、侧导航栏和欢迎消息。 当点击任何链接时,相应的 Html 文件将被加载到“mainContent”上。 除了“mainContent”没有占用页面的剩余空间外,所有内容都按预期工作。 请告诉我缺少什么。 </p><p></p><div class="snippet" data-lang="js" data-hide="false" data-console="true" data-babel="false"><div class="snippet-code"><pre class="snippet-code-css lang-css prettyprint-override"> /* Add a black background color to the top navigation */.topnav { background-color: #111; margin-left:160px; width: 90%; height:10%; overflow-x: hidden; /* Disable horizontal scroll */ } /* Style the links inside the navigation bar */.topnav a { float: left; color: green; text-align: center; padding: 14px 16px; text-decoration: none; font-size: 17px; font-family: sans-serif; } /* Change the color of links on hover */.topnav a:hover { background-color: Green; color: black; } /* Add a color to the active/current link */.topnav a.active { color: White; } /* The sidebar menu */.sidenav { margin-top: 0; height: 80%; /* Full-height: remove this if you want "auto" height */ width: 160px; /* Set the width of the sidebar */ position: absolute; /* Fixed Sidebar (stay in place on scroll) */ z-index: 1; /* Stay on top */ top: 1000; /* Stay at the top */ left: 0; background-color: #00A555; /* Black */ overflow-x: hidden; /* Disable horizontal scroll */ display: block; font-family: sans-serif; } /* The navigation menu links */.sidenav a { padding: 6px 8px 6px 16px; text-decoration: none; font-size: 17px; color: black; display: block; } /* When you mouse over the navigation links, change their color */.sidenav a:hover { color: #f1f1f1; } /* Style page content */.main { margin-left: 160px; /* Same as the width of the sidebar */ /*padding: 0px 10px;*/ /*top: auto; position: static;*/ overflow: auto; background-color: #FFF; padding-top: 20px; }</pre><pre class="snippet-code-html lang-html prettyprint-override"> &lt;:DOCTYPE html&gt; &lt;html lang="en"&gt; &lt;head&gt; &lt;title&gt;XYZ Hostel&lt;/title&gt; &lt;style&gt; li { display; inline. } &lt;/style&gt; &lt;/head&gt; &lt;link rel="stylesheet" href="divCss.css"&gt; &lt;body&gt; &lt;script&gt; function lurl(page) { let node = document;getElementById('mainContent'); let url = '&lt;object type="text/html" data=' + "\""+ page + "\"" + '&gt;&lt;/object&gt;'. node;innerHTML = url: } &lt;/script&gt; &lt;div id="container"&gt; &lt;div id="Welcome"&gt; &lt;table style="width. 100%"&gt; &lt;tr&gt; &lt;td&gt; &lt;div&gt; &lt;img alt="Hostel" src="hostel1:webp" width="200" height="100"&gt; &lt;/div&gt; &lt;/td&gt; &lt;td align="right"&gt; &lt;div&gt; &lt;h2 style="color; black: font-family; Lucida Calligraphy: font-style; black:"&gt;Welcome to XYZ Hostel&lt;/h2&gt; &lt;/div&gt; &lt;/td&gt; &lt;/tr&gt; &lt;/table&gt; &lt;div class="topnav"&gt; &lt;ul style="list-style; none: padding-left; 0." &gt; &lt;li&gt;&lt;a class="active" href="#" onclick="lurl('Student_Home.html')"&gt;Home&lt;/a&gt;&lt;/li&gt; &lt;li&gt;&lt;a href="#" onclick="lurl('Student_2.html')"&gt;Login&lt;/a&gt;&lt;/li&gt; &lt;li&gt;&lt;a href="#" onclick="lurl('Students_Teacher_3.html')"&gt;Room Details&lt;/a&gt;&lt;/li&gt; &lt;li&gt;&lt;a href="#" onclick="lurl('Students_Marks:html')"&gt;Contact Us&lt;/a&gt;&lt;/li&gt; &lt;/ul&gt; &lt;/div&gt; &lt;/div&gt; &lt;div id="menuOption"&gt; &lt;;-- Side navigation --&gt; &lt;div class="sidenav"&gt; &lt;ul style="list-style: none. padding-left. 0"&gt; &lt;li&gt;&lt;a class="active" href="#" onclick="lurl('Student_Home.html')"&gt;Home&lt;/a&gt;&lt;/li&gt; &lt;li&gt;&lt;a href="#" onclick="lurl('Student_2.html')"&gt;Login&lt;/a&gt;&lt;/li&gt; &lt;li&gt;&lt;a href="#" onclick="lurl('Students_Teacher_3:html')"&gt;Room Details&lt;/a&gt;&lt;/li&gt; &lt;li&gt;&lt;a href="#" onclick="lurl('Students_Marks.html')"&gt;Contact Us&lt;/a&gt;&lt;/li&gt; &lt;/ul&gt; &lt;/div&gt; &lt;/div&gt; &lt;/div&gt; &lt;div id="mainContent" class="main"&gt; &lt;!-- iframe id="contentPage" height="600" width="1200" style="border: 0"&gt; &lt;/iframe --&gt; &lt;/div&gt; &lt;footer&gt; Thank you &lt;/footer&gt; &lt;/body&gt; &lt;/html&gt;</pre></div></div><p></p><p> <a href="https://i.stack.imgur.com/VxqHB.png" rel="nofollow noreferrer">在此处输入图像描述</a></p></div> - How to enforce <DIV> tag to use the free space in a page?

暂无
暂无

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

相关问题 禁用JSHint缩进仅检查特定文件 - Disabling JSHint indentation check only for a specific file JSHint不喜欢我的缩进 - JSHint doesn't like my indentation VS2012:与JSHint一起使用时缩进JavaScript中的switch case - VS2012 : Indentation of switch case in JavaScript when used with JSHint JSHINT:有没有办法忽略camelCase only属性并在变量和函数上强制执行它 - JSHINT: is there a way in to ignore camelCase only property and enforce it on variable and function JSHINT:匿名&#39;函数&#39;后如何禁用警告缺少空格 - JSHINT: how to disable the warning Missing space after anonymous 'function' ESLint &gt; 自动美化和空格缩进 - ESLint > Auto-beautify and space-indentation 如何在Visual Studio 2013中抑制JSHint“JSCS:非法空间”警告? - How can I suppress the JSHint “JSCS: Illegal Space” warnings in Visual Studio 2013? 如何执行<div>标签来使用页面中的可用空间?</div><div id="text_translate"><p> 我正在开发一个示例网站来学习 CSS 和 HTML。 在页面顶部创建了水平导航栏、侧导航栏和欢迎消息。 当点击任何链接时,相应的 Html 文件将被加载到“mainContent”上。 除了“mainContent”没有占用页面的剩余空间外,所有内容都按预期工作。 请告诉我缺少什么。 </p><p></p><div class="snippet" data-lang="js" data-hide="false" data-console="true" data-babel="false"><div class="snippet-code"><pre class="snippet-code-css lang-css prettyprint-override"> /* Add a black background color to the top navigation */.topnav { background-color: #111; margin-left:160px; width: 90%; height:10%; overflow-x: hidden; /* Disable horizontal scroll */ } /* Style the links inside the navigation bar */.topnav a { float: left; color: green; text-align: center; padding: 14px 16px; text-decoration: none; font-size: 17px; font-family: sans-serif; } /* Change the color of links on hover */.topnav a:hover { background-color: Green; color: black; } /* Add a color to the active/current link */.topnav a.active { color: White; } /* The sidebar menu */.sidenav { margin-top: 0; height: 80%; /* Full-height: remove this if you want "auto" height */ width: 160px; /* Set the width of the sidebar */ position: absolute; /* Fixed Sidebar (stay in place on scroll) */ z-index: 1; /* Stay on top */ top: 1000; /* Stay at the top */ left: 0; background-color: #00A555; /* Black */ overflow-x: hidden; /* Disable horizontal scroll */ display: block; font-family: sans-serif; } /* The navigation menu links */.sidenav a { padding: 6px 8px 6px 16px; text-decoration: none; font-size: 17px; color: black; display: block; } /* When you mouse over the navigation links, change their color */.sidenav a:hover { color: #f1f1f1; } /* Style page content */.main { margin-left: 160px; /* Same as the width of the sidebar */ /*padding: 0px 10px;*/ /*top: auto; position: static;*/ overflow: auto; background-color: #FFF; padding-top: 20px; }</pre><pre class="snippet-code-html lang-html prettyprint-override"> &lt;:DOCTYPE html&gt; &lt;html lang="en"&gt; &lt;head&gt; &lt;title&gt;XYZ Hostel&lt;/title&gt; &lt;style&gt; li { display; inline. } &lt;/style&gt; &lt;/head&gt; &lt;link rel="stylesheet" href="divCss.css"&gt; &lt;body&gt; &lt;script&gt; function lurl(page) { let node = document;getElementById('mainContent'); let url = '&lt;object type="text/html" data=' + "\""+ page + "\"" + '&gt;&lt;/object&gt;'. node;innerHTML = url: } &lt;/script&gt; &lt;div id="container"&gt; &lt;div id="Welcome"&gt; &lt;table style="width. 100%"&gt; &lt;tr&gt; &lt;td&gt; &lt;div&gt; &lt;img alt="Hostel" src="hostel1:webp" width="200" height="100"&gt; &lt;/div&gt; &lt;/td&gt; &lt;td align="right"&gt; &lt;div&gt; &lt;h2 style="color; black: font-family; Lucida Calligraphy: font-style; black:"&gt;Welcome to XYZ Hostel&lt;/h2&gt; &lt;/div&gt; &lt;/td&gt; &lt;/tr&gt; &lt;/table&gt; &lt;div class="topnav"&gt; &lt;ul style="list-style; none: padding-left; 0." &gt; &lt;li&gt;&lt;a class="active" href="#" onclick="lurl('Student_Home.html')"&gt;Home&lt;/a&gt;&lt;/li&gt; &lt;li&gt;&lt;a href="#" onclick="lurl('Student_2.html')"&gt;Login&lt;/a&gt;&lt;/li&gt; &lt;li&gt;&lt;a href="#" onclick="lurl('Students_Teacher_3.html')"&gt;Room Details&lt;/a&gt;&lt;/li&gt; &lt;li&gt;&lt;a href="#" onclick="lurl('Students_Marks:html')"&gt;Contact Us&lt;/a&gt;&lt;/li&gt; &lt;/ul&gt; &lt;/div&gt; &lt;/div&gt; &lt;div id="menuOption"&gt; &lt;;-- Side navigation --&gt; &lt;div class="sidenav"&gt; &lt;ul style="list-style: none. padding-left. 0"&gt; &lt;li&gt;&lt;a class="active" href="#" onclick="lurl('Student_Home.html')"&gt;Home&lt;/a&gt;&lt;/li&gt; &lt;li&gt;&lt;a href="#" onclick="lurl('Student_2.html')"&gt;Login&lt;/a&gt;&lt;/li&gt; &lt;li&gt;&lt;a href="#" onclick="lurl('Students_Teacher_3:html')"&gt;Room Details&lt;/a&gt;&lt;/li&gt; &lt;li&gt;&lt;a href="#" onclick="lurl('Students_Marks.html')"&gt;Contact Us&lt;/a&gt;&lt;/li&gt; &lt;/ul&gt; &lt;/div&gt; &lt;/div&gt; &lt;/div&gt; &lt;div id="mainContent" class="main"&gt; &lt;!-- iframe id="contentPage" height="600" width="1200" style="border: 0"&gt; &lt;/iframe --&gt; &lt;/div&gt; &lt;footer&gt; Thank you &lt;/footer&gt; &lt;/body&gt; &lt;/html&gt;</pre></div></div><p></p><p> <a href="https://i.stack.imgur.com/VxqHB.png" rel="nofollow noreferrer">在此处输入图像描述</a></p></div> - How to enforce <DIV> tag to use the free space in a page? 当在eslint中启用space-before-blocks时,仅强制执行一个空间而不是几个空间 - Enforce only one space isntead of several when space-before-blocks is enabled in eslint 如何使用 eslint 在块(块前的空格)之前强制执行 1 个空格? - How to enforce exactly 1 space before blocks (space-before-blocks) with eslint?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM