Browse Source

Enable more linting rules (#486)

pull/490/head
Gabe Gorelick 7 years ago committed by Sergi Almacellas Abellana
parent
commit
6c3cdc2130
  1. 40
      .eslintrc.js
  2. 2
      Gruntfile.js
  3. 47
      papaparse.js
  4. 6
      tests/node-tests.js
  5. 6
      tests/test-cases.js

40
.eslintrc.js

@ -20,8 +20,8 @@ module.exports = { @@ -20,8 +20,8 @@ module.exports = {
"arrow-body-style": "error",
"arrow-parens": "error",
"arrow-spacing": "error",
"block-scoped-var": "off",
"block-spacing": "off",
"block-scoped-var": "error",
"block-spacing": "error",
"brace-style": "off",
"callback-return": "error",
"camelcase": ["error", {"properties": "never"}],
@ -44,8 +44,8 @@ module.exports = { @@ -44,8 +44,8 @@ module.exports = {
"default-case": "error",
"dot-location": "error",
"dot-notation": "error",
"eol-last": "off",
"eqeqeq": "off",
"eol-last": "error",
"eqeqeq": "error",
"for-direction": "error",
"func-call-spacing": "error",
"func-name-matching": "error",
@ -64,11 +64,14 @@ module.exports = { @@ -64,11 +64,14 @@ module.exports = {
"id-length": "off",
"id-match": "error",
"implicit-arrow-linebreak": "error",
"indent": ["error", "tab"],
"indent": [
"error",
"tab"
],
"indent-legacy": "off",
"init-declarations": "off",
"jsx-quotes": "error",
"key-spacing": "off",
"key-spacing": "error",
"keyword-spacing": "off",
"line-comment-position": "off",
"linebreak-style": [
@ -90,11 +93,11 @@ module.exports = { @@ -90,11 +93,11 @@ module.exports = {
"error",
"always-multiline"
],
"new-parens": "off",
"new-parens": "error",
"newline-after-var": "off",
"newline-before-return": "off",
"newline-per-chained-call": "off",
"no-alert": "off",
"no-alert": "error",
"no-array-constructor": "error",
"no-await-in-loop": "error",
"no-bitwise": "error",
@ -163,11 +166,11 @@ module.exports = { @@ -163,11 +166,11 @@ module.exports = {
"no-restricted-modules": "error",
"no-restricted-properties": "error",
"no-restricted-syntax": "error",
"no-return-assign": "off",
"no-return-assign": "error",
"no-return-await": "error",
"no-script-url": "error",
"no-self-compare": "error",
"no-sequences": "off",
"no-sequences": "error",
"no-shadow": "off",
"no-shadow-restricted-names": "error",
"no-spaced-func": "error",
@ -192,7 +195,7 @@ module.exports = { @@ -192,7 +195,7 @@ module.exports = {
"no-useless-rename": "error",
"no-useless-return": "off",
"no-var": "off",
"no-void": "off",
"no-void": "error",
"no-warning-comments": "error",
"no-whitespace-before-property": "error",
"no-with": "error",
@ -200,7 +203,7 @@ module.exports = { @@ -200,7 +203,7 @@ module.exports = {
"error",
"any"
],
"object-curly-newline": "off",
"object-curly-newline": ["error", {"consistent": true}],
"object-curly-spacing": "off",
"object-shorthand": "off",
"one-var": "off",
@ -230,8 +233,8 @@ module.exports = { @@ -230,8 +233,8 @@ module.exports = {
"require-await": "error",
"require-jsdoc": "off",
"rest-spread-spacing": "error",
"semi": "off",
"semi-spacing": "off",
"semi": "error",
"semi-spacing": "error",
"semi-style": [
"error",
"last"
@ -239,13 +242,16 @@ module.exports = { @@ -239,13 +242,16 @@ module.exports = {
"sort-imports": "error",
"sort-keys": "off",
"sort-vars": "off",
"space-before-blocks": "off",
"space-before-function-paren": "off",
"space-before-blocks": "error",
"space-before-function-paren": [
"error",
"never"
],
"space-in-parens": [
"error",
"never"
],
"space-infix-ops": "off",
"space-infix-ops": "error",
"space-unary-ops": [
"error",
{

2
Gruntfile.js

@ -18,4 +18,4 @@ module.exports = function(grunt) { @@ -18,4 +18,4 @@ module.exports = function(grunt) {
grunt.registerTask('build', ['uglify']);
grunt.registerTask('default', ['uglify']);
}
};

47
papaparse.js

@ -163,7 +163,7 @@ @@ -163,7 +163,7 @@
queue.splice(0, 1);
parseNextFile();
}
}
};
}
@ -617,11 +617,11 @@ @@ -617,11 +617,11 @@
this._chunkError();
else
this._start += this._config.chunkSize;
}
};
this._chunkLoaded = function()
{
if (xhr.readyState != 4)
if (xhr.readyState !== 4)
return;
if (xhr.status < 200 || xhr.status >= 400)
@ -632,13 +632,13 @@ @@ -632,13 +632,13 @@
this._finished = !this._config.chunkSize || this._start > getFileSize(xhr);
this.parseChunk(xhr.responseText);
}
};
this._chunkError = function(errorMessage)
{
var errorText = xhr.statusText || errorMessage;
this._sendError(new Error(errorText));
}
};
function getFileSize(xhr)
{
@ -687,7 +687,7 @@ @@ -687,7 +687,7 @@
{
if (!this._finished && (!this._config.preview || this._rowCount < this._config.preview))
this._readChunk();
}
};
this._readChunk = function()
{
@ -700,7 +700,7 @@ @@ -700,7 +700,7 @@
var txt = reader.readAsText(input, this._config.encoding);
if (!usingAsyncReader)
this._chunkLoaded({ target: { result: txt } }); // mimic the async signature
}
};
this._chunkLoaded = function(event)
{
@ -708,12 +708,12 @@ @@ -708,12 +708,12 @@
this._start += this._config.chunkSize;
this._finished = !this._config.chunkSize || this._start >= this._input.size;
this.parseChunk(event.target.result);
}
};
this._chunkError = function()
{
this._sendError(reader.error);
}
};
}
FileStreamer.prototype = Object.create(ChunkStreamer.prototype);
@ -730,7 +730,7 @@ @@ -730,7 +730,7 @@
{
remaining = s;
return this._nextChunk();
}
};
this._nextChunk = function()
{
if (this._finished) return;
@ -739,7 +739,7 @@ @@ -739,7 +739,7 @@
remaining = size ? remaining.substr(size) : '';
this._finished = !remaining;
return this.parseChunk(chunk);
}
};
}
StringStreamer.prototype = Object.create(StringStreamer.prototype);
StringStreamer.prototype.constructor = StringStreamer;
@ -761,7 +761,7 @@ @@ -761,7 +761,7 @@
this._input.on('data', this._streamData);
this._input.on('end', this._streamEnd);
this._input.on('error', this._streamError);
}
};
this._nextChunk = function()
{
@ -773,7 +773,7 @@ @@ -773,7 +773,7 @@
{
parseOnData = true;
}
}
};
this._streamData = bindFunction(function(chunk)
{
@ -977,7 +977,7 @@ @@ -977,7 +977,7 @@
if (_config.dynamicTypingFunction && _config.dynamicTyping[field] === undefined) {
_config.dynamicTyping[field] = _config.dynamicTypingFunction(field);
}
return (_config.dynamicTyping[field] || _config.dynamicTyping) === true
return (_config.dynamicTyping[field] || _config.dynamicTyping) === true;
}
function parseDynamic(field, value)
@ -1007,7 +1007,8 @@ @@ -1007,7 +1007,8 @@
{
var row = _config.header ? {} : [];
for (var j = 0; j < _results.data[i].length; j++)
var j;
for (j = 0; j < _results.data[i].length; j++)
{
var field = j;
var value = _results.data[i][j];
@ -1062,8 +1063,8 @@ @@ -1062,8 +1063,8 @@
for (var j = 0; j < preview.data.length; j++)
{
if (skipEmptyLines && preview.data[j].length === 1 && preview.data[j][0].length === 0) {
emptyLinesCount++
continue
emptyLinesCount++;
continue;
}
var fieldCount = preview.data[j].length;
avgFieldCount += fieldCount;
@ -1096,7 +1097,7 @@ @@ -1096,7 +1097,7 @@
return {
successful: !!bestDelim,
bestDelimiter: bestDelim
}
};
}
function guessLineEndings(input)
@ -1175,7 +1176,7 @@ @@ -1175,7 +1176,7 @@
comments = false;
// Newline must be valid: \r, \n, or \r\n
if (newline != '\n' && newline != '\r' && newline != '\r\n')
if (newline !== '\n' && newline !== '\r' && newline !== '\r\n')
newline = '\n';
// We're gonna need these at the Parser scope
@ -1238,6 +1239,7 @@ @@ -1238,6 +1239,7 @@
var nextDelim = input.indexOf(delim, cursor);
var nextNewline = input.indexOf(newline, cursor);
var quoteCharRegex = new RegExp(escapeChar.replace(/[-[\]/{}()*+?.\\^$|]/g, '\\$&') + quoteChar, 'g');
var quoteSearch;
// Parser loop
for (;;)
@ -1246,7 +1248,7 @@ @@ -1246,7 +1248,7 @@
if (input[cursor] === quoteChar)
{
// Start our search for the closing quote where the cursor is
var quoteSearch = cursor;
quoteSearch = cursor;
// Skip the opening quote
cursor++;
@ -1405,7 +1407,7 @@ @@ -1405,7 +1407,7 @@
var spaceLength = 0;
if (index !== -1) {
var textBetweenClosingQuoteAndIndex = input.substring(quoteSearch + 1, index);
if (textBetweenClosingQuoteAndIndex && textBetweenClosingQuoteAndIndex.trim() == '') {
if (textBetweenClosingQuoteAndIndex && textBetweenClosingQuoteAndIndex.trim() === '') {
spaceLength = textBetweenClosingQuoteAndIndex.length;
}
}
@ -1464,7 +1466,8 @@ @@ -1464,7 +1466,8 @@
function doStep()
{
step(returnable());
data = [], errors = [];
data = [];
errors = [];
}
};

6
tests/node-tests.js

@ -7,7 +7,7 @@ var assert = require('assert'); @@ -7,7 +7,7 @@ var assert = require('assert');
var longSampleRawCsv = fs.readFileSync(__dirname + '/long-sample.csv', 'utf8');
function assertLongSampleParsedCorrectly(parsedCsv) {
assert.equal(8, parsedCsv.data.length)
assert.equal(8, parsedCsv.data.length);
assert.deepEqual(parsedCsv.data[0], [
'Grant',
'Dyer',
@ -16,7 +16,7 @@ function assertLongSampleParsedCorrectly(parsedCsv) { @@ -16,7 +16,7 @@ function assertLongSampleParsedCorrectly(parsedCsv) {
'2014-05-31T01:06:56-07:00',
'Magna Ut Associates',
'ljenkins'
])
]);
assert.deepEqual(parsedCsv.data[7], [
'Talon',
'Salinas',
@ -33,7 +33,7 @@ function assertLongSampleParsedCorrectly(parsedCsv) { @@ -33,7 +33,7 @@ function assertLongSampleParsedCorrectly(parsedCsv) {
"truncated": false,
"cursor": 1209
});
assert.equal(parsedCsv.errors.length, 0)
assert.equal(parsedCsv.errors.length, 0);
}
describe('PapaParse', function() {

6
tests/test-cases.js

@ -1,6 +1,8 @@ @@ -1,6 +1,8 @@
var chai;
var Papa;
if (typeof module !== 'undefined' && module.exports) {
var chai = require('chai');
var Papa = require('../papaparse.js');
chai = require('chai');
Papa = require('../papaparse.js');
}
var assert = chai.assert;

Loading…
Cancel
Save