This repository was archived by the owner on Mar 23, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 509
/
Copy pathdisallow-mixed-spaces-and-tabs.js
84 lines (75 loc) · 1.81 KB
/
disallow-mixed-spaces-and-tabs.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
/**
* Requires lines to not contain both spaces and tabs consecutively,
* or spaces after tabs only for alignment if "smart"
*
* Types: `Boolean` or `String`
*
* Values: `true` or `"smart"`
*
* JSHint: [`smarttabs`](http://www.jshint.com/docs/options/#smarttabs)
*
* #### Example
*
* ```js
* "disallowMixedSpacesAndTabs": true
* ```
*
* ##### Valid example for mode `true`
*
* ```js
* \tvar foo = "blah blah";
* \s\s\s\svar foo = "blah blah";
* \t/**
* \t\s*
* \t\s*\/ //a single space to align the star in a multi-line comment is allowed
* ```
*
* ##### Invalid example for mode `true`
*
* ```js
* \t\svar foo = "blah blah";
* \s\tsvar foo = "blah blah";
* ```
*
* ##### Valid example for mode `"smart"`
*
* ```js
* \tvar foo = "blah blah";
* \t\svar foo = "blah blah";
* \s\s\s\svar foo = "blah blah";
* \t/**
* \t\s*
* \t\s*\/ //a single space to align the star in a multi-line comment is allowed
* ```
*
* ##### Invalid example for mode `"smart"`
*
* ```js
* \s\tsvar foo = "blah blah";
* ```
*/
var assert = require('assert');
module.exports = function() {};
module.exports.prototype = {
configure: function(options) {
assert(
options === true || options === 'smart',
this.getOptionName() + ' option requires a true value or "smart"'
);
this._options = options;
},
getOptionName: function() {
return 'disallowMixedSpacesAndTabs';
},
check: function(file, errors) {
var test = this._options === true ?
(/ \t|\t [^\*]|\t $/) :
(/ \t/);
file.iterateTokensByType('Whitespace', function(token) {
var match = test.exec(token.value);
if (match) {
errors.add('Mixed spaces and tabs found', token, token.index);
}
});
}
};