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
Conversation
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 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 |
Thanks, I appreciate the consideration. Also note:
|
That makes sense for me, and thanks for the tip to use Do you think my idea to use eslint-plugin-prettier to clean up the formatting in one shot makes sense? |
@brodybits I don't have any experience with that, but doing more rather than less makes sense to me. I've usually found |
I saw an excellent argument recently on Twitter: accessibility I think I lost the first one I saw, think I found another one:
https://www.reddit.com/r/javascript/comments/c8drjo/nobody_talks_about_the_real_reason_to_use_tabs/ |
There was a problem hiding this 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"; |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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.
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; | ||
} | ||
} |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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.
Maybe we can already land the |
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?
+1 I will likely do that soon
--
Sent from my mobile
|
as originally proposed in PR #90 Co-authored-by: Austin Wright <aaa@bzfx.net> Co-authored-by: Chris Brody <chris.brody+brodybits@gmail.com>
There was a problem hiding this 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.
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. |
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=1This is mostly just a suggestion, it's easy enough to go with a different style if something else is more popular.
After this: