Add ESLint.
[mootools.git] / Grunt / plugins / eslint / rules / mootools-whitespace.js
blobbd0ffc98d101633c6333bd3fc5f73727d4739119
1 'use strict';
3 var rules = [
4         {regex: /function\s+\(/g, message: 'Unexpected whitespace between "function" and "("'},
5         {regex: /\)\s+{/g, message: 'Unexpected whitespace between ")" and "{"'},
6         {regex: /(catch|for|if|switch|while|with)\(/g, message: 'Expected whitespace between "%s" and "(" but found none'},
7         {regex: /}(catch|else|finally)/g, message: 'Expected whitespace between "}" and "%s" but found none'},
8         {regex: /(do|else|finally|try){/g, message: 'Expected whitespace between "%s" and "{" but found none'}
9 ];
11 module.exports = function(context){
12         var errors = [];
14         function checkForIrregularWhitespace(node){
15                 context.getSourceLines().forEach(function(line, index){
16                         rules.forEach(function(rule){
17                                 var loc,
18                                         match;
20                                 while ((match = rule.regex.exec(line)) !== null){
21                                         loc = {
22                                                 line: index + 1,
23                                                 column: match.index
24                                         };
25                                         errors.push([node, loc, rule.message.replace('%s', match[1])]);
26                                 }
27                         });
28                 });
29         }
31         return {
32                 'Program': function(node){
33                         checkForIrregularWhitespace(node);
34                 },
35                 'Program:exit': function(){
36                         errors.forEach(function(error){
37                                 context.report.apply(context, error);
38                         });
39                 }
40         };
43 module.exports.schema = [];