UNPKG

809 BJavaScriptView Raw
1/**
2 * Disallows usage of specified keywords.
3 *
4 * Type: `Array`
5 *
6 * Values: Array of quoted keywords
7 *
8 * #### Example
9 *
10 * ```js
11 * "disallowKeywords": ["with"]
12 * ```
13 *
14 * ##### Invalid
15 *
16 * ```js
17 * with (x) {
18 * prop++;
19 * }
20 * ```
21 */
22
23var assert = require('assert');
24
25module.exports = function() {};
26
27module.exports.prototype = {
28
29 configure: function(keywords) {
30 assert(Array.isArray(keywords), this.getOptionName() + ' option requires array value');
31 this._keywords = keywords;
32 },
33
34 getOptionName: function() {
35 return 'disallowKeywords';
36 },
37
38 check: function(file, errors) {
39 file.iterateTokensByTypeAndValue('Keyword', this._keywords, function(token) {
40 errors.add('Illegal keyword: ' + token.value, token);
41 });
42 }
43
44};