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 | var assert = require('assert');
|
38 |
|
39 | var defaultKeywords = require('../utils').spacedKeywords;
|
40 | var ignoredKeywords = ['function'];
|
41 |
|
42 | module.exports = function() {};
|
43 |
|
44 | module.exports.prototype = {
|
45 |
|
46 | configure: function(keywords) {
|
47 | var isValidObject = (keywords === Object(keywords) && keywords.hasOwnProperty('allExcept'));
|
48 |
|
49 | assert(
|
50 | Array.isArray(keywords) || keywords === true || isValidObject,
|
51 | this.getOptionName() + ' option requires array, object with "allExcept" property or true value');
|
52 |
|
53 | var excludedKeywords = ignoredKeywords;
|
54 | if (isValidObject) {
|
55 | excludedKeywords = keywords.allExcept;
|
56 | }
|
57 |
|
58 | if (!Array.isArray(keywords)) {
|
59 | keywords = defaultKeywords.filter(function(keyword) {
|
60 | return (excludedKeywords.indexOf(keyword) === -1);
|
61 | });
|
62 | }
|
63 |
|
64 | this._keywords = keywords;
|
65 | },
|
66 |
|
67 | getOptionName: function() {
|
68 | return 'requireSpaceBeforeKeywords';
|
69 | },
|
70 |
|
71 | check: function(file, errors) {
|
72 | file.iterateTokensByTypeAndValue('Keyword', this._keywords, function(token) {
|
73 | var prevToken = file.getPrevToken(token, {includeComments: true});
|
74 | if (!prevToken || prevToken.isComment) {
|
75 | return;
|
76 | }
|
77 |
|
78 | if (prevToken.type !== 'Punctuator' || prevToken.value !== ';') {
|
79 | errors.assert.whitespaceBetween({
|
80 | token: prevToken,
|
81 | nextToken: token,
|
82 | message: 'Missing space before "' + token.value + '" keyword'
|
83 | });
|
84 | }
|
85 | });
|
86 | }
|
87 |
|
88 | };
|