Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add eslint #477

Merged
merged 1 commit into from
Apr 10, 2018
Merged

Add eslint #477

merged 1 commit into from
Apr 10, 2018

Conversation

gabegorelick
Copy link
Contributor

The goal is to make PapaParse friendlier for new developers.

The eslint config was generated from eslint --init with some tweaking of the resulting rules to minimize errors.

@@ -251,9 +252,6 @@

function JsonToCsv(_input, _config)
{
var _output = '';
var _fields = [];
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

These were never used.

? _input.fields
: objectKeys(_input.data[0]);
? _input.fields
: objectKeys(_input.data[0]);
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We can relax the rules if we're not concerned with indentation like this. But it was easier to just fix this case.

@@ -644,8 +642,8 @@
{
var contentRange = xhr.getResponseHeader('Content-Range');
if (contentRange === null) { // no content range, then finish!
return -1;
}
return -1;
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good example of catching stuff that's completely wrong.

var remaining;
this.stream = function(s)
{
string = s;
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This was never read.

@@ -1238,7 +1235,7 @@

var nextDelim = input.indexOf(delim, cursor);
var nextNewline = input.indexOf(newline, cursor);
var quoteCharRegex = new RegExp(escapeChar.replace(/[\-\[\]\/\{\}\(\)\*\+\?\.\\\^\$\|]/g, '\\$&')+quoteChar, 'g');
var quoteCharRegex = new RegExp(escapeChar.replace(/[-[\]/{}()*+?.\\^$|]/g, '\\$&')+quoteChar, 'g');
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We can relax https://eslint.org/docs/rules/no-useless-escape, but I think the resulting regex is easier to read.

@@ -1401,17 +1398,17 @@
/**
* checks if there are extra spaces after closing quote and given index without any text
* if Yes, returns the number of spaces
*/
function extraSpaces(index) {
var spaceLength = 0;
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Mixed tabs and spaces

player/player.js Outdated
var stepped = 0, chunks = 0, rows = 0;
var start, end;
var parser;
var parser; // eslint-disable-line no-unused-vars
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not sure if this is used as part of player.html so I kept it in.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I will prefer to keep player as is and ignore it.

@@ -1,64 +1,61 @@
(function() {
"use strict";
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I removed the IIFE wrapper. Didn't seem necessary in a node-only context and it caused eslint to flag the use of sync node APIs at the "top level" (since IIFE is not the top level).

@@ -825,7 +825,7 @@ var PARSE_TESTS = [
input: 'A,B,C\r\n1,2.2,1e3,5.5\r\n-4,-4.5,-4e-5',
config: { header: true, dynamicTyping: { A: true, C: true, __parsed_extra: true } },
expected: {
data: [{"A": 1, "B": "2.2", "C": 1000, "__parsed_extra": [ 5.5 ]}, {"A": -4, "B": "-4.5", "C": -0.00004}],
data: [{"A": 1, "B": "2.2", "C": 1000, "__parsed_extra": [5.5]}, {"A": -4, "B": "-4.5", "C": -0.00004}],
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We can relax stylistic stuff like this.

@gabegorelick
Copy link
Contributor Author

gabegorelick commented Apr 9, 2018

Tests are failing since eslint doesn't support Node.js 0.12. Since that reached end of life at the end of 2016, I think we should just drop support for that. I'll open a separate PR for that. Otherwise, I can switch to an older eslint version.

@pokoli
Copy link
Collaborator

pokoli commented Apr 9, 2018

I've merged the drop of 0.12, you should rebase to make the test pass.

@gabegorelick
Copy link
Contributor Author

@pokoli Thanks. Tests are passing now.

package.json Outdated
@@ -47,9 +48,10 @@
"serve-static": "^1.7.1"
},
"scripts": {
"lint": "eslint --no-ignore papaparse.js Gruntfile.js .eslintrc.js 'player/**/*.js' 'tests/**/*.js'",
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we can remove the player folder from lint and focus only on other files.

Player is here only for local testing

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done.

The goal is to make PapaParse friendlier for new developers.
@pokoli
Copy link
Collaborator

pokoli commented Apr 9, 2018

As a general note I will prefer to not relax the style and keep the recomended features

Thanks for your time on this.

I will do a last review tomorrow before merging.

@pokoli pokoli merged commit f32186a into mholt:master Apr 10, 2018
@gabegorelick gabegorelick deleted the eslint branch April 10, 2018 15:01
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants