Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Showing
6 changed files
with
177 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
# Disallow tabs in file (no-tabs) | ||
|
||
some style guides don't allow the use of tab characters anywhere. So they would want to disallow tab anywhere inside a file including comments. | ||
|
||
## Rule Details | ||
|
||
This rule looks for tabs inside the file. It can abe anywhere inside code or comments or anything. | ||
|
||
Examples of **incorrect** code for this rule: | ||
|
||
```js | ||
var a /t= 2; | ||
|
||
/** | ||
* /t/t its a test function | ||
*/ | ||
function test(){} | ||
|
||
var x = 1; // /t test | ||
``` | ||
|
||
Examples of **correct** code for this rule: | ||
|
||
```js | ||
var a = 2; | ||
|
||
/** | ||
* its a test function | ||
*/ | ||
function test(){} | ||
|
||
var x = 1; // test | ||
``` | ||
|
||
## When Not To Use It | ||
|
||
If you have established a standard where having tabs is fine. | ||
|
||
## Compatibility | ||
|
||
* **JSCS**: [disallowTabs](http://jscs.info/rule/disallowTabs) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
/** | ||
* @fileoverview Rule to check for tabs inside a file | ||
* @author Gyandeep Singh | ||
*/ | ||
|
||
"use strict"; | ||
|
||
//------------------------------------------------------------------------------ | ||
// Helpers | ||
//------------------------------------------------------------------------------ | ||
const regex = /\t/; | ||
|
||
//------------------------------------------------------------------------------ | ||
// Public Interface | ||
//------------------------------------------------------------------------------ | ||
|
||
module.exports = { | ||
meta: { | ||
docs: { | ||
description: "Disallow tabs in file", | ||
category: "Stylistic Issues", | ||
recommended: false | ||
}, | ||
schema: [] | ||
}, | ||
|
||
create(context) { | ||
return { | ||
Program(node) { | ||
context.getSourceLines().forEach((line, index) => { | ||
const match = regex.exec(line); | ||
|
||
if (match) { | ||
context.report( | ||
node, | ||
{ | ||
line: index + 1, | ||
column: match.index + 1 | ||
}, | ||
"Unexpected tab character." | ||
); | ||
} | ||
}); | ||
} | ||
}; | ||
} | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,86 @@ | ||
/** | ||
* @fileoverview Tests for no-tabs rule | ||
* @author Gyandeep Singh | ||
*/ | ||
"use strict"; | ||
|
||
//------------------------------------------------------------------------------ | ||
// Requirements | ||
//------------------------------------------------------------------------------ | ||
|
||
const rule = require("../../../lib/rules/no-tabs"); | ||
const RuleTester = require("../../../lib/testers/rule-tester"); | ||
|
||
//------------------------------------------------------------------------------ | ||
// Tests | ||
//------------------------------------------------------------------------------ | ||
|
||
const ruleTester = new RuleTester(); | ||
const ERROR_MESSAGE = "Unexpected tab character."; | ||
|
||
ruleTester.run("no-tabs", rule, { | ||
valid: [ | ||
"function test(){\n}", | ||
"function test(){\n" + | ||
" // sdfdsf \n" + | ||
"}", | ||
], | ||
invalid: [ | ||
{ | ||
code: "function test(){\t}", | ||
errors: [{ | ||
message: ERROR_MESSAGE, | ||
line: 1, | ||
column: 18 | ||
}] | ||
}, | ||
{ | ||
code: "/** \t comment test */", | ||
errors: [{ | ||
message: ERROR_MESSAGE, | ||
line: 1, | ||
column: 6 | ||
}] | ||
}, | ||
{ | ||
code: | ||
"function test(){\n" + | ||
" //\tsdfdsf \n" + | ||
"}", | ||
errors: [{ | ||
message: ERROR_MESSAGE, | ||
line: 2, | ||
column: 6 | ||
}] | ||
}, | ||
{ | ||
code: | ||
"function\ttest(){\n" + | ||
" //sdfdsf \n" + | ||
"}", | ||
errors: [{ | ||
message: ERROR_MESSAGE, | ||
line: 1, | ||
column: 10 | ||
}] | ||
}, | ||
{ | ||
code: | ||
"function test(){\n" + | ||
" //\tsdfdsf \n" + | ||
"\t}", | ||
errors: [ | ||
{ | ||
message: ERROR_MESSAGE, | ||
line: 2, | ||
column: 6 | ||
}, | ||
{ | ||
message: ERROR_MESSAGE, | ||
line: 3, | ||
column: 2 | ||
} | ||
] | ||
} | ||
] | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters