Skip to content
This repository has been archived by the owner on Mar 23, 2024. It is now read-only.

3.0 merge #2101

Merged
merged 82 commits into from
Jan 27, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
82 commits
Select commit Hold shift + click to select a range
b4acae0
Internal: remove babel-core types, add cst, remove XJS nodes
hzoo Nov 14, 2015
8fd954f
Internal: add cst - js-file, errors, string-checker
hzoo Nov 14, 2015
2e982a4
Internal: fix up tests, node.parentNode -> node.parentElement
hzoo Nov 14, 2015
a64b9c7
Internal: Line -> LineComment, Block -> BlockComment
hzoo Nov 14, 2015
09a1377
Internal: overall improvements
hzoo Nov 14, 2015
780cab8
Internal: strictmode false to make it easier for now, fix up tests
hzoo Nov 15, 2015
cbfd167
Reporters: add line/column
hzoo Nov 21, 2015
906e754
JS-file: correct error output & augment cst parser options
markelog Nov 28, 2015
a8ff7c1
JS-file: replace `File::iterateTokenByValue` with `selectTokensByValue`
markelog Nov 28, 2015
0d16099
add missing comma
hzoo Nov 28, 2015
db27e7f
Misc: fix more errors of js-file API
markelog Dec 9, 2015
b4f4f76
Misc: squash
markelog Dec 10, 2015
ca419ed
js-file: remove `getNodesByFirstToken` method
markelog Dec 16, 2015
12242d6
js-file: use new (slow) logic for `getFirstLineToken` method
markelog Dec 16, 2015
d080bc7
js-file: use new (slow) logic for `getLastTokenOnLine` method
markelog Dec 16, 2015
37c1372
Tests: correct `describe` text
markelog Dec 16, 2015
bb83502
js-file: Correct Parser options
markelog Dec 16, 2015
c640c65
Misc: use latest cst commit
markelog Dec 16, 2015
7dcb99a
js-file: fundamental improvements
markelog Dec 16, 2015
0626080
Tests: make jshint happy
markelog Dec 16, 2015
a331045
js-file: correct JSDoc
markelog Dec 16, 2015
908ab09
js-file: improve logic of the `setWhitespaceBefore` method
markelog Dec 16, 2015
8bbdc88
token-assert: correct logic of `linesBetween` method
markelog Dec 18, 2015
5e20d1a
js-file: improve `setWhitespaceBefore` method
markelog Dec 20, 2015
fbffba2
Errors: introduce static `getPosition` helper
markelog Dec 20, 2015
065fac2
token-assert: remove `(no)tokenBefore` methods
markelog Dec 20, 2015
bcbf487
token-assert: correct indentation tests & improve comments logic
markelog Dec 20, 2015
e3ce5e0
Tests: small test results corrections
markelog Dec 20, 2015
8bca93b
Tests: move pragma errors tests to `describe` and skip them
markelog Dec 20, 2015
4c68664
validateQuoteMarks: adapt to cst logic
markelog Dec 20, 2015
22ec695
Tests: skip couple tests
markelog Dec 20, 2015
a70e501
disallowMultipleLineBreaks: correct logic and tests for cst integration
markelog Dec 20, 2015
296f8cd
js-file: `getPrevToken` shouldn't return whitespace token
markelog Dec 20, 2015
9244350
string-checker: show correct errors from "_fix" methods
markelog Dec 20, 2015
add769f
disallowQuotedKeysInObjects: use cst methods for autofix
markelog Dec 20, 2015
ae5e558
disallowSemicolons: correct autofix tests
markelog Dec 20, 2015
13486cd
requireSemicolons: make this rule work with cst
markelog Dec 20, 2015
bc7129b
disallowSpaceAfterKeywords: correct one broken test
markelog Dec 20, 2015
e5de4cf
Errors: use end column instead of start column
markelog Dec 20, 2015
493c5cf
Tests: small corrections
markelog Dec 20, 2015
8152ac9
Tests: add `skip` option to `reportAndFix` signature
markelog Dec 21, 2015
a08f26c
string-checker: correct error reporting at parser error
markelog Dec 21, 2015
43a4537
disallowSpacesInGenerator: adapt to the CST environment
markelog Dec 21, 2015
6efb5c3
disallowSpacesInsideBrackets: use more precise iterate method
markelog Dec 21, 2015
7c7eaaf
Misc: use more precise iterate methods
markelog Dec 21, 2015
97bb3b2
disallowSpacesInsideParentheses: make small corrections for CST
markelog Dec 21, 2015
6e1718a
disallowTrailingComma: adapt to CST environment
markelog Dec 21, 2015
51f923c
js-file: correct line search for whitespace tokens
markelog Dec 21, 2015
a84bd67
disallowTrailingWhitespace: down to 9 failures
markelog Dec 21, 2015
a6a7948
Tests: clean-up couple tests
markelog Dec 25, 2015
9175804
disallowVar: correct rule logic
markelog Dec 25, 2015
03ca92f
requireAlignedObjectValues: skip complex test
markelog Dec 25, 2015
1e71d98
string-checker: restore value of `MAX_FIX_ATTEMPTS` constant
markelog Dec 25, 2015
be352ba
requireDollarBeforejQueryAssignment: do not try to use removed method
markelog Dec 26, 2015
81407e2
requireMultipleVarDecl: accomodate to cst
markelog Dec 26, 2015
c41f1f3
errors: make length of the code a default offset
markelog Dec 26, 2015
f80faff
js-file: don't jump through tokens in `getWhitespaceBefore` method
markelog Dec 27, 2015
3012321
requirePaddingNewlinesBeforeKeywords: accommodate to cst
markelog Dec 27, 2015
b5c26aa
errors: take start column not the end one
markelog Dec 27, 2015
2039775
requireQuotedKeysInObjects: make it autofixable
markelog Dec 27, 2015
829f726
errors: improve pointer placement
markelog Dec 27, 2015
01db115
disallowSemicolons: simplify `_fix` method
markelog Dec 27, 2015
fb0e740
requireSpaceAfterKeywords: correct flaky test
markelog Dec 27, 2015
a754845
Tests: correct column positions
markelog Dec 27, 2015
94ae2da
requireSpacesInsideParentheses: accommodate to cst
markelog Dec 27, 2015
e1cd43c
requireTrailingComma: temporary disable tests
markelog Dec 27, 2015
aa27ad7
errors: temporary disable errors tests
markelog Dec 27, 2015
5da8347
Tests: skip and fix some of tests
markelog Dec 27, 2015
251771b
Misc: make linters happy
markelog Dec 27, 2015
fabf956
errors:string-checker: correctly handle parse errors
markelog Dec 27, 2015
c56a424
test: remove ".only" call
markelog Dec 30, 2015
67a90fd
requireEnhancedObjectLiterals: make it autofixable
markelog Dec 30, 2015
f2847fd
Misc: bump the cst version
markelog Dec 30, 2015
5877b1c
requireEnhancedObjectLiterals: remove child before replacing it
markelog Dec 30, 2015
51e38bd
Convert disallow-unused-params to CST
mdevils Jan 10, 2016
1a3b5ab
Misc: skip test that uses ClassProperty until it's supported in CST
hzoo Jan 27, 2016
ca8ad5e
Misc: use node.parentElement
hzoo Jan 27, 2016
19f143c
Misc: fix parser error about return outside of a function
hzoo Jan 27, 2016
1a79f6c
Misc: skip test until CST fix
hzoo Jan 27, 2016
54bbb80
Misc: fixup error locs and use node.parentElement
hzoo Jan 27, 2016
cbadc4e
Misc: check if parserError has no loc property
hzoo Jan 27, 2016
22be818
Misc: fixup semicolons
hzoo Jan 27, 2016
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
111 changes: 78 additions & 33 deletions lib/errors.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,24 +27,21 @@ Errors.prototype = {
/**
* Adds style error to the list
*
* @param {String} message
* @param {Number|Object} line
* @param {Number} [column] optional if line is an object
* @param {String | Error} message
* @param {cst.types.Element} element
* @param {Number} [offset] relative offset
*/
add: function(message, line, column) {
if (typeof line === 'object') {
column = line.column;
line = line.line;
add: function(message, element, offset) {
if (message instanceof Error) {
this._addParseError(message);
return;
}

var errorInfo = {
this._addError({
message: message,
line: line,
column: column
};

this._validateInput(errorInfo);
this._addError(errorInfo);
element: element,
offset: offset || element.sourceCodeLength
});
},

/**
Expand All @@ -61,18 +58,20 @@ Errors.prototype = {
this._addError(errorInfo);
},

_validateInput: function(errorInfo) {
var line = errorInfo.line;
var column = errorInfo.column;

// line and column numbers should be explicit
assert(typeof line === 'number' && line > 0,
'Unable to add an error, `line` should be a number greater than 0 but ' +
line + ' given');

assert(typeof column === 'number' && column >= 0,
'Unable to add an error, `column` should be a positive number but ' +
column + ' given');
/**
* Adds parser error to error list.
*
* @param {Object} errorInfo
* @private
*/
_addParseError: function(errorInfo) {
this._errorList.push({
filename: this._file.getFilename(),
rule: 'parseError',
message: errorInfo.message,
line: errorInfo.loc && errorInfo.loc.line,
column: errorInfo.loc && errorInfo.loc.column
});
},

/**
Expand All @@ -82,18 +81,19 @@ Errors.prototype = {
* @private
*/
_addError: function(errorInfo) {
if (!this._file.isEnabledRule(this._currentRule, errorInfo.line)) {
if (!this._file.isEnabledRule(this._currentRule, errorInfo.element)) {
return;
}

this._validateInput(errorInfo);

var position = Errors.getPosition(errorInfo.element);
this._errorList.push({
filename: this._file.getFilename(),
rule: this._currentRule,
message: this._prepareMessage(errorInfo),
line: errorInfo.line,
column: errorInfo.column,
element: errorInfo.element,
line: position.line,
column: position.column,
offset: errorInfo.offset,
additional: errorInfo.additional,
fixed: errorInfo.fixed
});
Expand All @@ -106,8 +106,10 @@ Errors.prototype = {
* @private
*/
_prepareMessage: function(errorInfo) {
if (this._verbose && this._currentRule) {
return this._currentRule + ': ' + errorInfo.message;
var rule = errorInfo instanceof Error ? 'parseError' : this._currentRule;

if (this._verbose && rule) {
return rule + ': ' + errorInfo.message;
}

return errorInfo.message;
Expand Down Expand Up @@ -140,6 +142,17 @@ Errors.prototype = {
return this._errorList.length === 0;
},

/**
* Returns amount of errors added by the rules.
*
* @returns {Number}
*/
getValidationErrorCount: function() {
return this._errorList.filter(function(error) {
return error.rule !== 'parseError' && error.rule !== 'internalError';
});
},

/**
* Returns amount of errors added by the rules.
*
Expand Down Expand Up @@ -267,4 +280,36 @@ function renderPointer(column, colorize) {
return colorize ? chalk.grey(res) : res;
}

/**
* Get position of the element
* TODO: 3.0 - need to account for non-zero offset
*
* @param {Object} [element]
* @return {Object}
*/
Errors.getPosition = function(element) {
if (!element || !element.loc) {
return {
line: 0,
column: 0
};
}

var startColumn = element.loc.start.column;
var endColumn = element.loc.end.column;
var column;

if (element.sourceCodeLength === 1) {
column = startColumn;

} else {
column = startColumn + Math.ceil((endColumn - startColumn) / 2);
}

return {
line: element.loc.start.line,
column: column
};
};

module.exports = Errors;
Loading