coffeelint/lib/coffeelint.js in coffeelint-1.16.0 vs coffeelint/lib/coffeelint.js in coffeelint-1.16.1
- old
+ new
@@ -1,10 +1,10 @@
(function(f){if(typeof exports==="object"&&typeof module!=="undefined"){module.exports=f()}else if(typeof define==="function"&&define.amd){define([],f)}else{var g;if(typeof window!=="undefined"){g=window}else if(typeof global!=="undefined"){g=global}else if(typeof self!=="undefined"){g=self}else{g=this}g.coffeelint = f()}})(function(){var define,module,exports;return (function e(t,n,r){function s(o,u){if(!n[o]){if(!t[o]){var a=typeof require=="function"&&require;if(!u&&a)return a(o,!0);if(i)return i(o,!0);var f=new Error("Cannot find module '"+o+"'");throw f.code="MODULE_NOT_FOUND",f}var l=n[o]={exports:{}};t[o][0].call(l.exports,function(e){var n=t[o][1][e];return s(n?n:e)},l,l.exports,e,t,n,r)}return n[o].exports}var i=typeof require=="function"&&require;for(var o=0;o<r.length;o++)s(r[o]);return s})({1:[function(require,module,exports){
module.exports={
"name": "coffeelint",
"description": "Lint your CoffeeScript",
- "version": "1.16.0",
+ "version": "1.16.1",
"homepage": "http://www.coffeelint.org",
"keywords": [
"lint",
"coffeescript",
"coffee-script"
@@ -1683,25 +1683,41 @@
description: 'This rule imposes a standard number of spaces to be used for\nindentation. Since whitespace is significant in CoffeeScript, it\'s\ncritical that a project chooses a standard indentation format and\nstays consistent. Other roads lead to darkness. <pre> <code>#\nEnabling this option will prevent this ugly\n# but otherwise valid CoffeeScript.\ntwoSpaces = () ->\n fourSpaces = () ->\n eightSpaces = () ->\n \'this is valid CoffeeScript\'\n\n</code>\n</pre>\nTwo space indentation is enabled by default.'
};
Indentation.prototype.tokens = ['INDENT', '[', ']', '.'];
- Indentation.prototype.keywords = ['->', '=>', '@', 'CATCH', 'CLASS', 'ELSE', 'FINALLY', 'FOR', 'FORIN', 'FOROF', 'IDENTIFIER', 'IF', 'LEADING_WHEN', 'LOOP', 'RETURN', 'SWITCH', 'THROW', 'TRY', 'UNTIL', 'WHEN', 'WHILE', 'YIELD'];
+ Indentation.prototype.keywords = ['->', '=>', '@', 'CATCH', 'CLASS', 'ELSE', 'FINALLY', 'FOR', 'FORIN', 'FOROF', 'IDENTIFIER', 'IF', 'LEADING_WHEN', 'LOOP', 'PROPERTY', 'RETURN', 'SWITCH', 'THROW', 'TRY', 'UNTIL', 'WHEN', 'WHILE', 'YIELD'];
function Indentation() {
this.arrayTokens = [];
}
Indentation.prototype.lintToken = function(token, tokenApi) {
- var currentLine, expected, ignoreIndent, isArrayIndent, isMultiline, lineNumber, lines, numIndents, previous, previousSymbol, ref, ref1, ref2, type;
- type = token[0], numIndents = token[1], (ref = token[2], lineNumber = ref.first_line);
+ var chain, currentLine, dotIndent, expected, got, ignoreIndent, isArrayIndent, isMultiline, lineNumber, lines, next, numIndents, previous, previousSymbol, ref, ref1, ref2, startsWith, type;
+ type = token[0], numIndents = token[1];
+ dotIndent = token[2].first_column;
lines = tokenApi.lines, lineNumber = tokenApi.lineNumber;
expected = tokenApi.config[this.rule.name].value;
if (type === '.') {
currentLine = lines[lineNumber];
- if (((ref1 = currentLine.match(/\S/)) != null ? ref1[0] : void 0) === '.') {
- return this.handleChain(tokenApi, expected);
+ if (((ref = currentLine.match(/\S/)) != null ? ref[0] : void 0) === '.') {
+ next = tokenApi.peek(1);
+ if (next[0] === 'PROPERTY') {
+ chain = '.' + next[1];
+ startsWith = new RegExp('\\S{' + chain.length + '}');
+ if (((ref1 = currentLine.match(startsWith)) != null ? ref1[0] : void 0) === chain) {
+ got = dotIndent;
+ if (dotIndent - expected > expected) {
+ got %= expected;
+ }
+ if (dotIndent % expected !== 0) {
+ return {
+ context: "Expected " + expected + " got " + got
+ };
+ }
+ }
+ }
}
return void 0;
}
if (type === '[' || type === ']') {
this.lintArray(token);
@@ -1732,46 +1748,9 @@
this.arrayTokens.push(token);
} else if (token[0] === ']') {
this.arrayTokens.pop();
}
return null;
- };
-
- Indentation.prototype.handleChain = function(tokenApi, expected) {
- var callStart, checkNum, currIsIndent, currentLine, currentSpaces, findCallStart, lastCheck, lineNumber, lines, numIndents, prevIsIndent, prevLine, prevNum, prevSpaces, ref, ref1;
- lastCheck = 1;
- callStart = 1;
- prevNum = 1;
- lineNumber = tokenApi.lineNumber, lines = tokenApi.lines;
- currentLine = lines[lineNumber];
- findCallStart = tokenApi.peek(-callStart);
- while (findCallStart && findCallStart[0] !== 'TERMINATOR') {
- lastCheck = findCallStart[2].first_line;
- callStart += 1;
- findCallStart = tokenApi.peek(-callStart);
- }
- while ((lineNumber - prevNum > lastCheck) && !/^\s*\./.test(lines[lineNumber - prevNum])) {
- prevNum += 1;
- }
- checkNum = lineNumber - prevNum;
- if (checkNum >= 0) {
- prevLine = lines[checkNum];
- if (prevLine.match(/\S/)[0] === '.' || checkNum === lastCheck) {
- currentSpaces = (ref = currentLine.match(/\S/)) != null ? ref.index : void 0;
- prevSpaces = (ref1 = prevLine.match(/\S/)) != null ? ref1.index : void 0;
- numIndents = currentSpaces - prevSpaces;
- prevIsIndent = prevSpaces % expected !== 0;
- currIsIndent = currentSpaces % expected !== 0;
- if (prevIsIndent && currIsIndent) {
- numIndents = currentSpaces;
- }
- if (numIndents % expected !== 0) {
- return {
- context: "Expected " + expected + " got " + numIndents
- };
- }
- }
- }
};
Indentation.prototype.grabLineTokens = function(tokenApi, lineNumber, all) {
var i, k, len, len1, ref, ref1, results, results1, tok, tokensByLine;
if (all == null) {
\ No newline at end of file