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
Use standard
JavaScript Style
#4909
Conversation
Woo cool! |
This is ready for review! |
@zeke You're doin' the Lord's work, 👍 |
Is it possible to configure the mocha globals as only available inside the |
@@ -4,16 +4,32 @@ | |||
"devDependencies": { | |||
"asar": "^0.10.0", | |||
"eslint": "^2.1.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.
Could this now be removed?
Just include a |
@zeke do you think it is possible to avoid these completely in this PR? It would seem ideal to not have any pollution of standard/eslint comments like previously. |
@paulcbetts are you sure that works with
@kevinsawicki I agree. There were just a handful of spots in the code where I couldn't easily figure out how to refactor it without breaking the test suite. Perhaps we can pair tomorrow and try to knock them out? |
Sounds great 👍 ✖️ 💯 |
Yeah, I wasn't clear if it did either. Since there is a |
Edit: Hm, I have no idea if it works with standard, just copy-paste their eslintrc if it doesn't |
@paulcbetts:
I actually tried that format first, then tried the javascript format described in the eslint.org docs:
Good idea, but it didn't work. Perhaps @feross can give us some pointers? |
There's currently no way use If setting Add your globals to {
"lint": "standard && standard spec && python ./script/cpplint.py",
} |
I tested the My personal preference would be to keep all the config in the top-level package.json for the sake of discoverability/simplicity, and for the composability of running one command to lint all the javascript, instead of two. See https://github.com/atom/electron/blob/e342d65abb9d4df85fd508b55669b9eaf2c77681/package.json#L13-L24 The difference are subtle though. Either approach works for me. |
@kevinsawicki and I paired on this for a bit today. Here's what we got done:
Kevin said he'll review the outstanding pull requests and merge any that seem like they need to land first. Barring any other feedback or concerns from the rest of the team, this is ready to 🐑! |
})(); | ||
var _isVisible = true | ||
var _isMinimized = false | ||
;(function () { |
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.
Is this leading ;
required?
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.
'tis. We could name the function, then invoke it.
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.
We could name the function, then invoke it.
I'm in favor of doing this ☝️
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.
Done. 8a159de
standard-format freaks out on this line: let obj = new (Function.prototype.bind.apply(constructor, [null].concat(args))) http://stackoverflow.com/questions/1606797/use-of-apply-with-new-operato r-is-this-possible
I landed one and rebased this branch, no plans to merge any others before this lands. |
Let's merge this so we can merge other PRs. |
RIP git blame functionality |
We have lost him long time ago when converting coffee to js. |
@ichpuchtli you can git blame more than one level deep. |
I was curious what @bbondy meant regard multi-level git blame. So far I found |
This pull request migrates all of electron's JavaScript code to standard style.
Why use
standard
on a project like electron? Thestandard
README summarizes it well:The Rules
(
or[
if (condition) { ... }
function name (arg) { ... }
===
instead of==
– butobj == null
is allowed to checknull || undefined
.err
function parameterwindow
– exceptdocument
andnavigator
are okayopen
,length
,event
, andname
.For more details, see https://github.com/feross/standard/blob/master/RULES.md
The Refactor
I kicked off the refactor using standard-format to automatically convert much of the code. This got me a long way, but the tool has its share of issues. Sometimes it chokes on files containing valid syntax, and sometimes it overlooks files that contain invalid syntax.
¯\_(ツ)_/¯
After squeezing everything I could out of
standard-format
, I removed it from the dependencies because we probably won't need automated code refactoring once this refactor rolls out.Next I installed snazzy, a wrapper around
standard
that produces glamorous and colorful output. This was nice because it made the process of manual code cleanup much more... pleasant. As I made changes, I committed them often to ensure the test suite continued to pass.Once I got all the code cleaned up, I uninstalled
snazzy
in favor of vanillastandard
for a few reasons:standard
is more actively maintained thansnazzy
standard
is a more recognizable name for the dependencysnazzy
's output is a little buggy sometimesThe Most Common Fixes
Here's a sorted list of the most common errors, generated by standard-summary:
Globals
The test suite contains a number of global variables, mostly from mocha:
after
,afterEach
,before
,beforeEach
,Blob
,btoa
,describe
,DevToolsAPI
,Event
,fetch
,HTMLElement
,HTMLObjectElement
,InspectorFrontendHost
,it
,location
,MutationObserver
,Response
,self
,SharedWorker
,URL
,WebInspector
,WebSocket
,WebView
,Worker
,xdescribe
,xit
.These globals are whitelisted in a few different ways:
a
standard.globals
array in package.json is used for the most common repeat offenders, like mocha and jquery.a
/* globals foo, bar */
comment at the top of the offending file, for less commonly used globals.For more info, see the standard docs about globals
Ignoring Stuff
In package.json, there's an
ignore
array that accepts glob patterns for files and directories:To ignore a few lines of code, wrap them in these comments:
To ignore a single line of code, use a
// eslint-disable-line
comment:CoffeeScript Legacy
Back in January, the electron codebase was converted from Coffeescript to JavaScript. This automated refactor left behind a number of code artifacts, some of which have been cleaned up here.
All implicit returns that were doing assignment have been removed (e.g.
return foo = 1
). There are undoubtedly still lots of unneeded (yet syntactically valid) implicit returns left over.There's still plenty of leftover cruft from the coffeescript conversion, but most of it is harmless. Any time you see
ref =
in a javascript file, it's pretty safe to assume that it's old coffee code that could use some cleanup.Getting and Setting Prototype
Invoking Constructors
It works to leave off the parens, but don't do it:
Merging this PR
As @paulcbetts recently observed:
As of this writing, there are 15 open pull requests. We should decide which of those we want to land before this refactor, and which we should close or rebase post-standard.
Given the haphazard and compulsively granular commit history in this branch, I'd be happy to squash it all into a single commit if that's preferred by the team.