-
Notifications
You must be signed in to change notification settings - Fork 3.5k
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
[WIP] Use XO instead of Standard #723
Conversation
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.
Something is wrong with the tabs. A key isn't being assigned properly. After this works, we can merge it!
The tab thing is actually broken on master. Not the result of our changes! |
Fixes a bug introduced by #723
const uid = sessions.activeUid; | ||
const sessionUids = keys(sessions.sessions); | ||
if (uid === sessionUids[i]) { | ||
console.log('ignoring same uid'); | ||
} else if (null != sessionUids[i]) { |
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.
null != sessionUids[i]
checks for undefined
as well @matheuss, now you're explicitly checking for the value null
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.
That's true @ekmartin 😰 What do you think we should do?
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.
Set eqeqeq
to ["error", "always", {"null": "ignore"}]
and revert the == null
and != null
changes maybe?
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 know what makes sense in this context, but in general, checking against both null
and undefined
is an anti-pattern these days. Native things like "default parameters" only work on undefined
, not null
, so better to get used to null
meaning an empty value, and undefined
meaning no value.
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.
Generally I agree, however I'm a bit unsure when it comes to config values. If it never makes sense for a specific config value to be null it might be better to prevent plugins and similar from setting it as such.
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.
Then I would rather throw a TypeError
and be explicit about it.
But if you really want both undefined
and null
, I would strongly recommend just being verbose and explicit about it: sessionUid[i] !== undefined && sessionUid[i] !== null
. Not everyone knows that sessionUid[i] != null
coerces to the same. XO is about enforcing explicit and readable code.
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.
Sounds reasonable :)
var text = this.getSelectionText(); | ||
if (text != null && text !== '') { | ||
const text = this.getSelectionText(); | ||
if (text !== null && text !== '') { |
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.
same here, text as undefined
would get through text !== null
but not text != null
. Maybe if (text)
would suffice
@@ -91,71 +91,69 @@ const reducer = (state = initial, action) => { | |||
ret.fontSizeOverride = null; | |||
} | |||
|
|||
if (null != config.fontSize) { |
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.
same here
Awesome! Let me know if you have any concerns or questions. I'm happy to discuss any of the rule choices. There's a good reasoning behind every single rule. |
"react/no-string-refs": 0, | ||
"react/jsx-key": 0, | ||
"no-nested-ternary": 0, | ||
"react/jsx-no-bind": 0 | ||
}, |
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.
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.
"react/no-danger": 0, | ||
"react/no-string-refs": 0, | ||
"react/jsx-key": 0, | ||
"no-nested-ternary": 0, |
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 only a warning, but just removed this as I don't like how it works either: xojs/eslint-config-xo@d3944f6 (Planning a new release in a few weeks)
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.
👌
"babel/new-cap": 0, | ||
"quote-props": 0, | ||
"import/no-extraneous-dependencies": 0, | ||
"no-warning-comments": 0, |
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.
Why? It's useful to be reminded about TODO comments.
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.
"react/prop-types": 0, | ||
"babel/new-cap": 0, | ||
"quote-props": 0, | ||
"import/no-extraneous-dependencies": 0, |
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 assume this is because of complaining about the electron
import. This will be fixed with eslint-plugin-import@2 where they will allow XO to specify the builtin.
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.
"quote-props": 0, | ||
"import/no-extraneous-dependencies": 0, | ||
"no-warning-comments": 0, | ||
"complexity": 0, |
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.
Why? Complexity is usually a good metric of too many code paths. Was it too spammy? Should I increase the maximum (currently 20)?
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.
@@ -1,3 +1,4 @@ | |||
/* eslint-disable prefer-arrow-callback */ |
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.
Why not just use arrow functions?
@@ -1,6 +1,7 @@ | |||
const path = require('path'); | |||
|
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.
No need for an empty line here.
(fileStat['mode'] & parseInt('0100', 8)) | ||
(fileStat.mode & parseInt('0001', 8)) || | ||
(fileStat.mode & parseInt('0010', 8)) || | ||
(fileStat.mode & parseInt('0100', 8)) |
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.
No rule for this yet, but these should use octal literals instead of parseInt
.
@@ -188,7 +189,7 @@ lib.colors.hexToRGB = function (arg) { | |||
} | |||
|
|||
if (arg instanceof Array) { | |||
for (var i = 0; i < arg.length; i++) { | |||
for (let i = 0; i < arg.length; i++) { |
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.
Here it would be better to use a for..of
loop.
No rule for it yet, but consider me a linter :p
@@ -188,7 +189,7 @@ lib.colors.hexToRGB = function (arg) { | |||
} | |||
|
|||
if (arg instanceof Array) { |
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.
Use Array.isArray()
. instanceof won't work across realms (frames/iframes/vm).
@sindresorhus Just for clarity: Yes, disabling these rules is definitely a bad practise and I completely agree with you. Which is why we're going to break them down to zero. The only reason why I haven't did that before merging the PR was because it's a lot of work... 😊 As you can see in the issue description, I already put some effort into making the code comply with the rules, but these ones are left.
We're thankful for every helpful hand that we can get (especially for yours)! |
Ah, makes sense. I should have looked at the issue tracker before commenting. |
TODO:
There was a discussion in zeit.chat about changing the code style of HyperTerm's code base – and later on @zeit's code base (via @leo). We compared XO, Standard and Airbnb's JavaScript Style Guide.
Since I use XO in my projects and I'm very happy with the rules it enforces, I'm sending this PR so we can discuss changing HyperTerm's code style to XO's 😄
There was a lot of changes – many of them had to be done manually (
xo --fix
helped in the simpler ones), so I created a summary:Summary of changes
const { something } = require('module');
=>const {something} = require('module');
fn({ key: 'value' });
=>fn({key: 'value'});
function name () {...}
=>function name() {...}
(arg) => {...}
=>arg => {...}
<Tag prop='value'>
=><Tag prop="value">
return <Tag>;
=>return (<Tag>);
something("'");
=>something('\'');
let a, b, c;
=> onelet
per linewas changed to
was changed to
if ('object' !== typeof value)
=>if (typeof value !== 'object')
was changed to
if (something) return true;
was changed to
obj. hasOwnProperty(prop);
=>{}. hasOwnProperty.call(obj, prop);
==
,!==
=>===
,!==
Another changes
The
store
variable in Redux middlewares was removed when it's not used – 8a8fdac#diff-6c6a3219ca05ccbe3ce89f7544a8f40aR8Some rules relating to switch-case were disabled because the code was kinda complex and I didn't want to change it – 8a8fdac#diff-7da6d687f5a3beed5725bb8324e4b1adR82
The
babel/new-cap
rule was disabled due to things like this: 8a8fdac#diff-8303185c505c28257453bad1aadc768bR22For some reason (probably related to
this
binding) the (only) test we have couldn't be changed from standard functions to arrow functions – 8a8fdac#diff-f7cc7aca73879ae481a889ab216ba926R1React rules
There's currently 151 errors related to React code styling. Since I have 0 expertise with React, I didn't change anything related to it. Any help is more than welcome 😄
Conclusion
Since these changes affect every contributor, we need to discuss them carefully. I'm 100% open to any help, input and feedback about them.
A lot of the changes can affect how the code works, so any help with testing it is very welcome.