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

Lint with tabs & enable strict mode #90

Closed
wants to merge 2 commits into from
Closed

Conversation

awwright
Copy link
Contributor

@awwright awwright commented Jul 14, 2020

This adds an .eslintrc.js, .editorconfig, and normalizes the whitespace to 1-tab indents.

Btw, whitespace can be ignored from GitHub by adding ?w=1 to a diff URL: 2bbb7e2?w=1

This is mostly just a suggestion, it's easy enough to go with a different style if something else is more popular.

After this:

  • Fix remaining eslint errors with switch/break statements
  • Add eslint to CI tests
  • Enable additional eslint tests

@brodybits
Copy link
Member

Thanks. I have mixed feelings about using tabs at this point. My biggest worry with tabs is that they do not look so nice on Unix editors, especially on Linux & Unix.

I am starting to see your point in #29 that tabs can help avoid issues like 7-space indentation and 2-space vs 4-space indentation. It is also nice to see not all lines of the code suddenly reindented with spaces. I would be interested in what the other contributors & maintainers have to say about this idea.

It is possible to configure eslint in a YML file, which may be a little easier for us to update over time. It would also be possible to configure eslint per subdirectory tree, which would make it possible to format lib and test in separate PRs. An idea might be to format the tests first, then continue fixing the assertions in #89 before cleaning up lib.

I am also thinking we could use Prettier at the same time to solve both indentation and code formatting at the same time. I think this would be better than the extra code churn that would come from doing this in multiple steps. I think it should be pretty straightforward to add eslint and Prettier together using eslint-plugin-prettier.

A final comment on lib is that the test coverage of lib/entities.js is pretty bad, as you can see by following the report from the mutation score badge. It might be nice to cover remaining entries in lib/entities.js before reformatting it.

@awwright
Copy link
Contributor Author

Thanks, I appreciate the consideration. Also note:

  • GitHub reads .editorconfig, and will set tab widths to whatever is specified there.
  • On Linux and macOS you can run tabs -4 (or put it in your shell rc) which sets the tab stops to every 4 columns. (or whatever other number you like).

@brodybits brodybits changed the title Lint Lint with tabs Jul 14, 2020
@brodybits
Copy link
Member

That makes sense for me, and thanks for the tip to use ?w=1. I took the liberty to update the title, would like to give others some time for feedback before continuing with a possible merge.

Do you think my idea to use eslint-plugin-prettier to clean up the formatting in one shot makes sense?

@awwright
Copy link
Contributor Author

@brodybits I don't have any experience with that, but doing more rather than less makes sense to me. I've usually found --fix to be sufficient for formatting, except for some mixed-spaces-tabs problems.

@brodybits
Copy link
Member

I saw an excellent argument recently on Twitter: accessibility

I think I lost the first one I saw, think I found another one:

I was firmly in the camp of spaces only in source code (entered with the tab key, of course, and proper editor settings) until I read this about the accessibility benefits of using tab characters for indentation:https://t.co/TIASFjXcL8

— Tommy Williams (@twwilliams) January 24, 2020

https://www.reddit.com/r/javascript/comments/c8drjo/nobody_talks_about_the_real_reason_to_use_tabs/

Copy link
Member

@karfau karfau left a comment

Choose a reason for hiding this comment

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

I like the idea of adding a minimal linting setup, also regarding doing more of it if feasible, but I'm not so sure about applying "use strict"; before having more tests.

@@ -1,3 +1,5 @@
"use strict";
Copy link
Member

Choose a reason for hiding this comment

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

I don't have a clear understanding of the impact, might this be a breaking change?
According to MDN "Strict mode changes both syntax and runtime behavior.".
So I would rather wait for more tests to be available before making such a change.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

It's possible to statically determine all of the new errors strict mode might throw. Iirc, eslint raises errors for all of these cases by default.

Comment on lines +1194 to +1210
function getTextContent(node){
switch(node.nodeType){
case ELEMENT_NODE:
case DOCUMENT_FRAGMENT_NODE:
var buf = [];
node = node.firstChild;
while(node){
if(node.nodeType!==7 && node.nodeType !==8){
buf.push(getTextContent(node));
}
node = node.nextSibling;
}
return buf.join('');
default:
return node.nodeValue;
}
}
Copy link
Member

Choose a reason for hiding this comment

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

What is the reason for moving this function here? At first glance is seems to be unrelated to the linting changes. If so you could extract it into a separate PR.

Copy link
Contributor Author

@awwright awwright Aug 17, 2020

Choose a reason for hiding this comment

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

This function was previously inside an "if" statement, which is ambiguous behavior because of function hoisting; this is prohibited in strict mode.

@karfau
Copy link
Member

karfau commented Aug 17, 2020

Maybe we can already land the .editorconfig in an extra PR? So that all new contributions don't need to change when this PR lands?

@brodybits
Copy link
Member

brodybits commented Aug 17, 2020 via email

.editorconfig Outdated Show resolved Hide resolved
brodybits added a commit that referenced this pull request Aug 17, 2020
as originally proposed in PR #90

Co-authored-by: Austin Wright <aaa@bzfx.net>
Co-authored-by: Chris Brody <chris.brody+brodybits@gmail.com>
@brodybits brodybits changed the title Lint with tabs Lint with tabs & enable strict mode Aug 17, 2020
@brodybits brodybits added the bug Something isn't working label Aug 17, 2020
Copy link
Member

@brodybits brodybits left a comment

Choose a reason for hiding this comment

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

Thanks again to @awwright for your work on this.

Unfortunately I think we need to make these updates in multiple focused PRs, which I have already started working on.

More details are coming in a separate comment, since GitHub did not seem to do proper cross-referencing from review comments.

@brodybits
Copy link
Member

I have started making these changes in the following PRs:

As I said in PR #110, I would now favor that we do the formatting with Prettier all at once.

I think the changes to enable strict mode are also needed and should be done after we have finished with the eslint and/or Prettier formatting.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants