-
-
Notifications
You must be signed in to change notification settings - Fork 2.3k
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
New rule: Add linter for single arg fat arrow functions #309
Comments
… functions. This is the plugin implementation work for: standard/standard#309
FYI there's http://eslint.org/docs/rules/arrow-parens |
Even though I also omit parens on single arguments I don't see a lot of benefit in enforcing it. |
Can you send a PR with this change? Also, please run the tests and report how many of the repos in the test suite start to fail with this change. That should get the discussion started. |
I've seen a lot of bikeshedding around this issue in various projects which is why I think it would be good to enforce this one way or another. |
Some of this is discussed over here: standard/eslint-config-standard#14 Arrow functions specifically are well enough supported/understood that I think it makes sense to move forward with this specific rule. |
As discussed in: standard/standard#309
Submitted a PR in eslint-config-standard.
I'm happy to do this if needed, is there any documentation about how to run the tests? |
@KevinGrandon Just run |
Thanks. I assume that this should be run in eslint-config-standard? I ran with both "as-needed" (which I would like to implement), as well as "always". Results are as follows:
|
@feross - Does that test output look correct? ^ Any thoughts on implementing this rule since it seems most of the test repos follow it? |
I'm ambivalent about this proposed rule. But it does feel a bit inconsistent... to codify it:
I agree that no parenthesis looks cleaner. If I'm a noob to JavaScript, the rule feels inconsistent. It almost seems as if we should require parenthesis in all cases if we're gonna make a rule. To be clear, I support either. Maybe we defer until later? IDC. |
I can say this much, I usually write without the parenthesis in the single parameter case. But scanning over code like this: var foo = bar => {
window.alert(bar)
} I have to do a double take. Whereas code like this, feels easier to recognize: var foo = (bar) => {
window.alert(bar)
} All very subjective though. I think @feross will just have to pick something :) |
My personal preferences are in line with @jprichardson's. |
Agreed with @jprichardson. My habits are the same. Can we enforce the following: x => x
(x, y) => x + y
(x) => { return x } That way, the braced scope enforces parenthesis, but the 1 liner can be either. |
I am not sure it should be enforced but if we do I think @dcousens' proposal makes sense. |
@dcousens
|
Not sure I follow - you should pick one style with parens, or without. I've seen lots of bikeshedding about this issue in projects, and picking a style would fix that. My preference is to go without parens for single argument functions as I believe that it follows the current style of this guide, and it's the style that the test repos use. |
@KevinGrandon I think standard is the best readability focused guide. Let me reiterate:
|
@feross thoughts on: x => x
(x) => { return x }
(x, y) => x + y
(x, y) => { return x + y } The English of it is: no parenthesis for a 1 liner unless there is more than 1 argument. Parenthesis always if a braced expression exists. Meaning, of all the possible combinations (not many), the only one that is rejected is: x => {
return x
} |
Big 👍 on that. I'd prefer |
I think that let y = x => x + 1 vs let y = (x) => x + 1 may be confusing. But I commonly write someMethod(param1, param2, x => {
// do something
}) IDK, @feross, I think it's just one of those cases where you're gonna have to just pick something :) |
In light of a 'just pick something', I'd prefer @rstacruz's, that is, always |
If we go this route (enforcing a rule), this would be my preference as well - for the sake of consistency. |
It may be best to try to use built-in eslint rules if possible. Does this rule cover @rstacruz's preference? Is there overlap with your rule @KevinGrandon? |
looks like it does. |
I have personally taken to always (x) even with one liners, because of consistency with syntax rules, so I agree with adding it like @dcousens says. |
Using the new improved test suite that tests the top ~400 packages that use
3%
5% |
@jprichardson's point about consistency in this comment is really good. The overall sentiment of contributors is leaning towards @KevinGrandon Your original argument about consistency with the dangling comma rule was good, too. I think consistency helps readability and that was also the purpose of the dangling comma rule. I don't think this issue is super important, and consistency is preferable. Let's enable this in v6:
|
👍 awesome, I hate bike-shedding on this in my mind every time I write a 1-arg lambda. |
Will be released in standard 6 |
I may be late to the discussion, but while I think that the following is somewhat inconsistent: () => ... //parenths I think this could be avoided with: _ => .... //something common in functional languages In this way, 0 and 1 arg funcs could have no parentheses... forbidding |
seeing those errors in my editor this morning in regards to a single arg arrow func ... I found my way here. my initial reaction ... well, I didn't like it. but then after some thought, I do agree, it will be more consistent this way. I don't like extra typing when it can be avoided, but I also don't like one-off conventions such as the one @machadogj (not that it is invalid, I actually kinda like the idea of using |
* standard/standard#309 * FIX: error Expected parentheses around arrow function argument arrow-parens
Should this be documented somewhere, e.g. in the rules? |
My only objection is to not being allowed to use |
- Allow users to set the per_page option to 0 - 0.1.3 released - bugfix for archive disabled pagination when archive disabled pagination, per_page should be 0. - fix typo - Merge pull request #1 from wileam/patch-1 bugfix for archive disabled pagination - add archive daily - add tests - Merge pull request #2 from huanz/master add archive daily - Replace JSHint with ESLint and JSCS - 0.1.4 released - Fix: cannot deploy when src refspec is not master - Use HEAD src refspec to fix the problem - Merge pull request #4 from h404bi/master Fix: cannot deploy when src refspec is not master - Update README.md Clarify `branch` option - Use ESLint and JSCS - Set global git config for CI - 0.1.0 released - Allow users to set the per_page option to 0 - Merge pull request #2 from borisschapira/master Allow users to set the per_page option to 0 - 0.1.3 released - Set scrolling="no" to make iframe responsive the fiddle iframe is not responsive in iOS safari and Chrome. By setting `scrolling="no"` makes it possible to fix this issue, by setting `width=1px; min-width=100%` in CSS. [See StackOverflow](http://stackoverflow.com/questions/23083462/how-to-get-an-iframe-to-be-responsive-in-ios-safari) - fixed #1105 - Merge pull request #1345 from anjianshi/master fixed #1105 make url_for() handle "/" correctly - New date helper using momentjs 'fromNow' method Moment.js provides a quite useful function for relative time, it would be a shame not to use it ;) - Explicit comparisons - Do not compare undefined with null, explicit the cas instead - Decorrelate fromNow from output - date_fromNow tests - Now there is a function that apply locale and timezone and each helper format the date - [helper] add log() Good for logging objects in theme and plugin originally #1389 Changes to be committed: modified: lib/plugins/helper/debug.js modified: lib/plugins/helper/index.js new file: test/scripts/helpers/debug.js modified: test/scripts/helpers/index.js - Merge pull request #1391 from leesei/master [helper] add log() - Prepend root path to urlForHelper When user configures a prefix path as root path, urlForHelper can not resolve url like '/archives' correctly with the prefix root path. Resolves: #1105 - Merge pull request #1406 from liuhongjiang/add_root_to_urlForHelper Prepend root path to urlForHelper - now hexo list post will show category and tag what post been - add hexo list category(cate) - fix CI error - Modify the error Modify tag_id to category_id in line 153. - Use ESLint and JSCS instead of JSHint. Fix tests failed on Node.js 4 - Fix coding style - Add contributing guide - fix: #1451: more cannot work in almost all themes - fix "date" attribute default value - fix relative_url - fix: #1451: more cannot work in almost all themes - Merge branch 'fix_more_excerpt' of https://github.com/amobiz/hexo into HEAD - added line_number flag to code block, allowing for independent enabling/disabling of line numbers for each block - restricted trimming of tag bodies to the (presumably intended) cleaning up of occasionally parser-inserted extraneous line breaks. - added test - Merge pull request #1539 from aausch/correct_tag_trimming Correct tag trimming - might as well add a configuration option to enable/disable highlight all together. - unit test for highlight disable option - unit test for line_number option. - Fix https warning When blog is on https, there is warning if all resources are not on https... - Fix HTML issue with RSS/Atom feeds: rel="alternate" According to the W3C, "alternative" is not a valid value for attribute "rel" on element "link". The HTML5 standard uses <link rel="alternate" to provide an alternate representation, such as RSS or Atom. - Merge pull request #1572 from vhf/feed-tag-fix Fix HTML issue with RSS/Atom feeds: rel="alternate" - Merge pull request #1561 from nemanjan00/patch-1 Fix https warning - Merge pull request #1524 from zoubin/bugfix-relative_url fix relative_url - Merge pull request #1519 from amobiz/fix_more_excerpt Fix more excerpt - Fix gravatar helper tests failed and update deps - Merge pull request #1538 from aausch/block_configurable_line_numbers override line_number, highlight settings at the codeblock level - Merge pull request #1512 from Gtskk/patch-1 Modify the error - Merge pull request #1523 from aulphar/master fix "date" attribute default value #1522 - Merge branch 'master' of https://github.com/XGHeaven/hexo into XGHeaven-master # Conflicts: # lib/plugins/console/list/post.js - Merge branch 'XGHeaven-master' - Make JSCS happy - Fix the issue that we cannot use space in tag parameter which wrapped with double quote mark - fix the syntax warning - Fix the issue of jscs error - Fix post list console - Add abbrev. support for list console - Update hero-util to 0.2.1 - Merge branch 'master' of https://github.com/borisschapira/hexo into borisschapira-master # Conflicts: # lib/plugins/helper/date.js # test/scripts/helpers/date.js - Rename date_fromNow helper to relative_date - Disable auto detect for highlight by default - Replace sha1 with xxHash for faster checksum - Lazy load file hash - Load file hash only if the file is new or the modified time is changed - Lock the file when resolving the cache - Use g++-4.8 on Travis. Remove Node.js 0.10 build and add Node.js 5. - Use xxhash as optional dependency - Update warehouse to 2.0.0 - Detect the current category/tag in `is_category/tag` helper. Resolve #1278 - Fix Sha1Stream return raw buffer - Always use xxhash - 3.2.0-beta.1 released - tag: fix special tag names - jscs --fix - add option for first line number to tag.js - add option for first line number to test - delete extra blank line. - Use Promise.each in box process to prevent race condition - Use eslint-plugin-hexo and jscs-preset-hexo - Speed improvements Changes: - Rewrite Box. - Process files during loading file list. - Delay file hash check. Use File.changed() to check if file changed. - Remove watch delay. - Parallel processing. - Save rendered content in warehouse. It really saves a lot of time. - Rewrite generate console. - Cache rendered content so we don't have to render it again. - Load file list from cache. Don't delete other files in public folder. Resolve #1310 - Remove file stat check. - Parallel generating. - Resolve race conditions. Known issues: - Parallel processing and parallel generating may cause race conditions. We have to solve this in warehouse. - Tests are not updated yet. - Merge pull request #1607 from rhykw/add-firstLine-option-to-tag-plugin Added `first_line` option to codeblock - Merge pull request #1599 from magicdawn/fix-special-tags tag: fix special tag names - Merge pull request #1305 from tjwudi/master Set scrolling="no" to make iframe responsive - Merge pull request #1581 from winterTTr/master Fix issue cannot correctly analyze arguments with space in tag - Fix box tests. Emit processBefore & processAfter on Box instead of Hexo context. - Bug fixes. - Fix all other tests. - Listen to processAfter event of boxes. - Fix generate console not write file if not exist - Allow non-json file in data processor - Remove post asset if post was removed - Update hexo-util@0.3.0 and fix box tests on Linux - Merge branch 'new-box' - Fix JSCS error - Ignore node_modules folder in theme folder. Resolve #1316 - Implement include/exclude files - Merge config instead of extend - 3.2.0-beta.2 released - 解决code中存在类似swig语法被错误解析的问题 - Add headerlink for post render test cases - Update hexo-renderer-marked version - Ignore milliseconds for the post test cases - Fix cache key name error for box file test cases - Merge pull request #1668 from liuhongjiang/fix-test-errors Fix test errors - Merge pull request #1652 from ksky521/master 解决code中存在类似swig语法被错误解析的问题 - Support root path configure for img tag Current img tag doesn't prepend root path if it's not a slash. With this fix, the root path will be prepend to the img src if it's not a slash. This fix only works for the hexo tags, does not work for the markdown syntax of links and images. The issues of markdown links and images should be fixed in the hexo-renderer-marked module. Resolves: #1440 - Add root path to permalink of post This commit fixs this problem, when the root path is set to a subdirectory, there is no this root path in the permalink of post. - Merge pull request #1444 from liuhongjiang/prepend-root-to-img-tag Support root path configure for img tag - OpenGraph: added support for twitter image attribute - trim() instead of regular expression - keywords supported in open_graph - Update license date - Merge pull request #1697 from timwangdev/patch-2 Happy new year! - Remove unneccessary refs to type attr in helper output snippets. See Issue #1695: hexojs/hexo#1695 Also see the HTML5 Spec section on the type attr: http://dev.w3.org/html5/spec-preview/Overview.html#attr-link-type In short, the use of type tags is purely advisory, and the spec instructs browsers to infer the resource type before fetching them. In cases where the inference does not match the declaration, the resource will not be loaded. When the declaration is left off, the resource will load. It appears generally safer to leave the tags off entirely. - Revise tests to not expect type attrs in generated link/script tags. - url_for helper: Don't prepend root if url is started with # Fix #1708 - Ignore empty categories/tags. Fix #1704 - Fix skip_render doesn't work in asset generator - Allow specify plugin list in config. Resolve #1670 - Merge pull request #1706 from brycepj/1695-html5-type-remove Remove unneccessary refs to type attr in helper output snippets - Merge pull request #1681 from giuseppelt/giuseppelt-og-twitter OpenGraph: added support for twitter image attribute - Merge pull request #1683 from yanni4night/master keywords supported in open_graph - Update deps - Make linter happy - Use hero-log and remove commands exist in hexo-cli - Replace Swig in post.create - Remove bunyan - Add tests for config console - Update debug helper test with rewire - Update appveyor.yml - View render improvements - Use _.assign instead of _.extend - Simplify View.prototype._buildLocals - Precompile theme templates if possible - Update dependencies - Fix category path when placed on root This patch fixes the double slashes (http://site.com//cat1) in the category path, when you configure `category_dir` with '/' or '' - Merge branch 'giuseppelt-patch-1' - [fix] don't urlescape path of post asset fixes #1562 Changes to be committed: modified: lib/models/post_asset.js modified: test/scripts/tags/asset_img.js - [test] add spaced asset test for all post asset tags Changes to be committed: modified: test/scripts/tags/asset_img.js modified: test/scripts/tags/asset_link.js modified: test/scripts/tags/asset_path.js - [chore] make linter happy - [test] add test for number of lines in code block Changes to be committed: modified: test/scripts/tags/code.js - test(processor/post): should compare with birthtime - add mark option to code blocks closes #1766 - test(tags/code): update mark test Changes to be committed: modified: test/scripts/tags/code.js - lint(tags/code): make linter happy Changes to be committed: modified: lib/plugins/tag/code.js modified: test/scripts/tags/code.js - Load file status before Box.process - Remove File.changed method - There's no big difference to load file status in demand so I bring back file type "skip". - Fix tests failed on Windows since the incorrect path separator - Add test for Swig template compile - 3.2.0 released - fixes hexojs/hexo#1297 - Merge pull request #1 from borisschapira/master fixes hexojs/hexo#1297 - 0.1.3 released - Custom order for posts - Update README - Merge pull request #3 from iissnan/order-customization Custom order for posts - Replace JSHint with ESLint and JSCS - 0.2.0 released - Allow users to set the per_page option to 0 - Merge pull request #1 from borisschapira/master Allow users to set the per_page option to 0 - 0.1.2 released - allow to generate tag index page - update test for tag index page - Merge pull request #2 from creeperyang/AddIndexPage Add Tag index page - Use eslint-config-hexo and jscs-preset-hexo - 0.2.0 released - Add tests - 0.1.1 released - Add support for template precompile - 0.2.0 released - Use opn instead. Don't watch files in static mode. - Use eslint-config-hexo and jscs-preset-hexo - added process.env.port to facilitate configuration through process management utils (pm2/strongloop/forever/heroku). follows express convention - Merge pull request #16 from EvanCarroll/master added process.env.port to facilitate configuration through process ma… - 0.1.3 released - Update appveyor.yml - Add options and some improvements - Add "compress" option: Enable GZIP compression - Add "header" option: Add "X-Powered-By: Hexo" header - Display "0.0.0.0" as "localhost" - Use supertest-promised in tests - Make linter happy - Install superset as well - 0.2.0 released - Update readme - Upgrade dependencies. Fixes DoS in marked. Closes #3 - Merge pull request #14 from rstoenescu/master Upgrade dependencies. Fixes DoS in marked. - headerlink - mocha test error fix - Merge pull request #15 from ksky521/master headerlink - Use eslint-config-hexo and jscs-preset-hexo - 0.2.6 released - Strip html from headerlink title - add unit test for header links - Merge pull request #17 from cgmartin/patch-1 Strip html from headerlink title - 0.2.7 released - Prepend root path to img and link In hexo configuration, if the root path is set to a sub directory, hexo should prepend this root path to img and link of markdown syntax. Resolves: hexojs/hexo#1440 - Merge pull request #7 from liuhongjiang/prepend-root-to-img-link Prepend root path to img and link - 0.2.8 released - No prefix for anchor links Inserting links to headings directly from markdown is common practice. `[jump to title](#title)` should not become a full-blown URL on markdown rendering. It should instead be rendered as-is: `<a href="#title">jump to title</a>`. - Merge pull request #21 from vhf/no-prefix-for-anchor-links No prefix for anchor links - Don't prepend root path to links - 0.2.9 released - Use slugize method of hexo-util to fix Chinese headers can't be handle properly - 0.2.10 released - travis: add 4.0.0 - Merge pull request #16 from feross/dcousens-patch-1 travis: add 4.0.0 - badges - remove `browser: false` env option no-op - Relax radix rule Rule: http://eslint.org/docs/rules/radix.html Just tested latest Chrome, Firefox, Safari, and Edge and parseInt('071') returns 71 as expected. I think we can finally relax this rule. Code that uses parseInt and targets really old browsers should still use a radix, but this doesn't need to be a rule anymore. Discussion: standard/standard#384 - code style - BREAKING: require eslint 2.0.0 - config changes for eslint 2.0.0 - no-return-assign: make default option explicit - disallow label usage, even with loops/switch statements - fix config validation issue - New rule: Enforce spaces around * in "yield *" http://eslint.org/docs/2.0.0/rules/yield-star-spacing Fixes standard/standard#335 - enable jsx support for standard 6 standard v6 will not use the eslint sharable config “eslint-config-standard-react” anymore. So, let’s add support for jsx syntax in the parser in eslint-config-standard. Discussion: standard/standard#351 - travis: drop 0.10 and 0.12 support - New rule: Require parens in arrow function arguments http://eslint.org/docs/2.0.0/rules/arrow-parens.html Fixes standard/standard#309 - alphabetize package.json keywords - add promise/param-names rule Ensures that new Promise() is instantiated with the parameter names resolve, reject. Fixes standard/standard#282 - remove duplicate rule - New rule: Enforce Usage of Spacing in Template Strings (template-curly-spacing) http://eslint.org/docs/2.0.0/rules/template-curly-spacing - New rule: Disallow Symbol Constructor (no-new-symbol) http://eslint.org/docs/2.0.0/rules/no-new-symbol - New rule: Disallow Self Assignment (no-self-assign) http://eslint.org/docs/2.0.0/rules/no-self-assign - New rule: Disallow unnecessary constructor (no-useless-constructor) http://eslint.org/docs/2.0.0/rules/no-useless-constructor - New rule: Disallow string concatenation when using __dirname and __filename (no-path-concat) Fixes #403 http://eslint.org/docs/2.0.0/rules/no-path-concat - New rule: Disallow empty destructuring patterns (no-empty-pattern) http://eslint.org/docs/2.0.0/rules/no-empty-pattern - move jsx-quotes rule from eslint-config-standard-react - readme - test: fix for eslint 2 - 5.0.0 - fix tests - lock to latest versions - peer depend on eslint - 5.1.0 - Appveyor yml file - remove unnecessary options object manipulation - v6.0.2 - Revert "remove unnecessary options object manipulation" This reverts commit eb6319ff50ae8ef4f9f287fdd4d8f67ba083bba2. Turns out those options ARE relevant, for Minimatch, though not for glob. Oh well. Fix #239 - v6.0.3 - update badges to add appveyor and coveralls remove david-dm, since I don't really get much value out of it. I run 'npm outdated' enough to find issues. - add node 5 to travis-ci - simplify appveyor.yml file Also adds a few details that make things go faster - Upgrade to tap@4 Required a slight change since Istanbul now includes a fs.readdirSync(), which triggered the ENOTSUP test monkeypatch. - Fix appveyor install of node Thanks @appveyor support! - remove util._extend fix #240 - tap@5 - v6.0.4 - Raise error if cwd is not a directory Fix #235 - v7.0.0 - add package name to readme Fix #230 - changelog Fix #179 - Fix race condition when all patterns are ignored Fix #232 - v7.0.1 - Properly exclude dirs using nodir when root is set Fix #221 - update tap to 5.7.0 - v7.0.2 - test: fix some paths for windows - remove incorrect absolute-ness check in makeAbs - Prevent incorrect nodir results on Windows Ensure that everything in the cache always uses correct slashes, and always test against absolute paths when checking anything in the cache. - optimization: only abs the cwd once - v7.0.3
I've wrote some more thoughts regarding this in my PR, suggesting |
I think we should implement this rule in the following manner:
The reason being is that with only a single argument, the function is much easier to read without parens. Some folks who don't like this might argue about expansion and having a bigger diff when adding arguments down the road. Since we currently fail lint on trailing commas I think we should fail here on un-needed parens, it feels like it follows the same ideology as the trailing comma rule. (If we did enforce trailing commas, then I would probably enforce parens here as well).
I have a simple eslint plugin here that I'd be happy to include/relinquish: https://github.com/KevinGrandon/eslint-plugins/blob/master/lib/rules/arrow-function-parens.js
The text was updated successfully, but these errors were encountered: