SRCDIR=src
UPSTREAM=eslint
-UPSTREAMTAG=v7.0.0
+UPSTREAMTAG=v7.1.0
BUILDSRC=${UPSTREAM}-${UPSTREAMTAG}
all: ${DEB}
<!--
- ESLint adheres to the [JS Foundation Code of Conduct](https://js.foundation/community/code-of-conduct).
+ ESLint adheres to the Open JS Foundation Code of Conduct:
+ https://eslint.org/conduct
This template is for bug reports. If you are here for another reason, please see below:
1. To propose a new rule: https://eslint.org/docs/developer-guide/contributing/new-rules
2. To request a rule change: https://eslint.org/docs/developer-guide/contributing/rule-changes
3. To request a change that is not a bug fix, rule change, or new rule: https://eslint.org/docs/developer-guide/contributing/changes
- 4. If you have any questions, please stop by our chatroom: https://gitter.im/eslint/eslint
+ 4. If you have any questions, please stop by our chatroom: https://eslint.org/chat
Note that leaving sections blank will make it difficult for us to troubleshoot and we may have to close the issue.
-->
**What did you expect to happen?**
**What actually happened? Please include the actual, raw output from ESLint.**
-
---
<!--
- ESLint adheres to the [JS Foundation Code of Conduct](https://js.foundation/community/code-of-conduct).
+ ESLint adheres to the Open JS Foundation Code of Conduct:
+ https://eslint.org/conduct
This template is for bug reports. If you are here for another reason, please see below:
1. To propose a new rule: https://eslint.org/docs/developer-guide/contributing/new-rules
2. To request a rule change: https://eslint.org/docs/developer-guide/contributing/rule-changes
3. To request a change that is not a bug fix, rule change, or new rule: https://eslint.org/docs/developer-guide/contributing/changes
- 4. If you have any questions, please stop by our chatroom: https://gitter.im/eslint/eslint
+ 4. If you have any questions, please stop by our chatroom: https://eslint.org/chat
Note that leaving sections blank will make it difficult for us to troubleshoot and we may have to close the issue.
-->
+
**Tell us about your environment**
<!--
---
<!--
- ESLint adheres to the [JS Foundation Code of Conduct](https://js.foundation/community/code-of-conduct).
+ ESLint adheres to the Open JS Foundation Code of Conduct:
+ https://eslint.org/conduct
This template is for requesting a change that is not a bug fix, rule change, or new rule. If you are here for another reason, please see below:
1. To report a bug: https://eslint.org/docs/developer-guide/contributing/reporting-bugs
2. To request a rule change: https://eslint.org/docs/developer-guide/contributing/rule-changes
3. To propose a new rule: https://eslint.org/docs/developer-guide/contributing/new-rules
- 4. If you have any questions, please stop by our chatroom: https://gitter.im/eslint/eslint
+ 4. If you have any questions, please stop by our chatroom: https://eslint.org/chat
Note that leaving sections blank will make it difficult for us to troubleshoot and we may have to close the issue.
-->
+
+
**The version of ESLint you are using.**
---
<!--
- ESLint adheres to the [JS Foundation Code of Conduct](https://js.foundation/community/code-of-conduct).
+ ESLint adheres to the Open JS Foundation Code of Conduct:
+ https://eslint.org/conduct
This template is for new rule proposals. If you are proposing a new rule, please continue on. If you are here for another reason, please see below:
1. To report a bug: https://eslint.org/docs/developer-guide/contributing/reporting-bugs
2. To request a rule change: https://eslint.org/docs/developer-guide/contributing/rule-changes
3. To request a change that is not a bug fix, rule change, or new rule: https://eslint.org/docs/developer-guide/contributing/changes
- 4. If you have any questions, please stop by our chatroom: https://gitter.im/eslint/eslint
+ 4. If you have any questions, please stop by our chatroom: https://eslint.org/chat
Note that leaving sections blank will make it difficult for us to troubleshoot and we may have to close the issue.
-->
+
**Please describe what the rule should do:**
+
+**What new ECMAScript feature does this rule relate to?**
+
+<!-- New rules must be related to ECMAScript features added within the last 12 months -->
+
**What category of rule is this? (place an "X" next to just one item)**
[ ] Warns about a potential error (problem)
[ ] Suggests an alternate way of doing something (suggestion)
-[ ] Enforces code style (layout)
[ ] Other (please specify:)
**Provide 2-3 code examples that this rule will warn about:**
---
name: "â›” Question"
-about: Please go to https://gitter.im/eslint/eslint
+about: Please go to https://eslint.org/chat
title: ''
labels: ''
assignees: ''
---
<!--
- ESLint adheres to the [JS Foundation Code of Conduct](https://js.foundation/community/code-of-conduct).
-
+ ESLint adheres to the Open JS Foundation Code of Conduct:
+ https://eslint.org/conduct
Please do not use GitHub for asking questions. Instead,
please visit our chatroom:
- https://gitter.im/eslint/eslint
+ https://eslint.org/chat
Or our mailing list:
---
<!--
- ESLint adheres to the [JS Foundation Code of Conduct](https://js.foundation/community/code-of-conduct).
+ ESLint adheres to the Open JS Foundation Code of Conduct:
+ https://eslint.org/conduct
This template is for requesting a rule change. If you are here for another reason, please see below:
1. To report a bug: https://eslint.org/docs/developer-guide/contributing/reporting-bugs
2. To propose a new rule: https://eslint.org/docs/developer-guide/contributing/new-rules
3. To request a change that is not a bug fix, rule change, or new rule: https://eslint.org/docs/developer-guide/contributing/changes
- 4. If you have any questions, please stop by our chatroom: https://gitter.im/eslint/eslint
+ 4. If you have any questions, please stop by our chatroom: https://eslint.org/chat
Note that leaving sections blank will make it difficult for us to troubleshoot and we may have to close the issue.
-->
+
**What rule do you want to change?**
**Does this change cause the rule to produce more or fewer warnings?**
---
<!--
- ESLint adheres to the [JS Foundation Code of Conduct](https://js.foundation/community/code-of-conduct).
+ ESLint adheres to the Open JS Foundation Code of Conduct:
+ https://eslint.org/conduct
STOP! Please do not use GitHub for filing security issues.
#### Prerequisites checklist
- [ ] I have read the [contributing guidelines](https://github.com/eslint/eslint/blob/master/CONTRIBUTING.md).
-- [ ] The team has reached consensus on the changes proposed in this pull request. If not, I understand that the evaluation process will begin with this pull request and won't be merged until the team has reached consensus.
#### What is the purpose of this pull request? (put an "X" next to an item)
+v7.1.0 - May 22, 2020
+
+* [`a93083a`](https://github.com/eslint/eslint/commit/a93083af89c6f9714dcdd4a7f27c8655a0b0dba6) Fix: astUtils.getNextLocation returns invalid location after CRLF (#13275) (Milos Djermanovic)
+* [`df01af1`](https://github.com/eslint/eslint/commit/df01af184d93b3d64b37cee786cad59bd0d7aacb) Update: padded-blocks loc position changes (refs #12334) (#13328) (Anix)
+* [`bd3f092`](https://github.com/eslint/eslint/commit/bd3f092efa579944f75bfbc277b35f85e6d966ed) Fix: max-lines-per-function flagging arrow IIFEs (fixes #13332) (#13336) (cherryblossom000)
+* [`25462b2`](https://github.com/eslint/eslint/commit/25462b23eac4ed1ded97eeae6187b5d8baa58e78) Update: block-spacing changed loc for extra (refs #12334) (#13314) (Anix)
+* [`de0aab9`](https://github.com/eslint/eslint/commit/de0aab95005f172db72196fc3fd18e91ee9a5880) Fix: report end loc in one-var-declaration-per-line (refs #12334) (#13326) (YeonJuan)
+* [`1710296`](https://github.com/eslint/eslint/commit/1710296082083602a904b080908657bb431fb56c) Fix: no-new-symbol false positive with Symbol as an argument (#13337) (Milos Djermanovic)
+* [`cc01451`](https://github.com/eslint/eslint/commit/cc014514c29626e556acb0a528e3478b3725e284) Fix: arrow-parens no reporting for comments inside (fixes #12995) (#13312) (Anix)
+* [`a195141`](https://github.com/eslint/eslint/commit/a19514193a42f4f00732559ff828b33a6ec9d7c5) Update: reporting location for semi-spacing (refs #12334) (#13285) (Anix)
+* [`e3e4c41`](https://github.com/eslint/eslint/commit/e3e4c41ab625a5af8d4614d1c6d32c656f104f6b) Fix: fix false positives of no-new-func (#13333) (Pig Fang)
+* [`611c676`](https://github.com/eslint/eslint/commit/611c676dfd671013d81810724f184e2a9c5ad5d7) Docs: Update new rules policies (#13343) (Nicholas C. Zakas)
+* [`3a5fbb3`](https://github.com/eslint/eslint/commit/3a5fbb3d634be688615950c0a5fa8aead6ff08b5) Chore: correct fileoverview doc in accessor-pairs (#13335) (YeonJuan)
+* [`b0a6b81`](https://github.com/eslint/eslint/commit/b0a6b8134e3b399beeb69432a02232a1037f7c46) Update: Improve report location for rest-spread-spacing (refs #12334) (#13313) (Milos Djermanovic)
+* [`68c8ee3`](https://github.com/eslint/eslint/commit/68c8ee3ab70187972aef4c4e866bcf29da70a207) Fix: Stop path analyzer on unknown nodes (#13305) (Ilya Volodin)
+* [`89e1081`](https://github.com/eslint/eslint/commit/89e10811c4df666216aae58bff5f855cd9df738b) Update: Improve report location for linebreak-style (refs #12334) (#13317) (Milos Djermanovic)
+* [`0891379`](https://github.com/eslint/eslint/commit/08913798b4ec420b261b8fbc470504f9f248c840) Docs: Document the "correct" way to build an array with values (#13246) (Ed S)
+* [`88127d7`](https://github.com/eslint/eslint/commit/88127d74d56b88cc5a0758856995716050021131) Chore: remove checkbox from PR template prerequesites (#13330) (Kai Cataldo)
+* [`c636d57`](https://github.com/eslint/eslint/commit/c636d5708c461a8ff1ea55e5df56d4f76f9c4044) New: no-loss-of-precision (fixes #11279) (#12747) (jmoore914)
+* [`72a4e10`](https://github.com/eslint/eslint/commit/72a4e1044592057c4a3f39dbb1dbe61b00ea8af6) Chore: Mark SourceCode getComments() method as deprecated (fixes #13293) (#13296) (SuperOleg39)
+* [`7f14846`](https://github.com/eslint/eslint/commit/7f1484690665b4f4b9cd9680ca8bb7b5cf56e48a) Docs: fix broken link in Node.js API docs (#13307) (Kai Cataldo)
+* [`02aeba1`](https://github.com/eslint/eslint/commit/02aeba19afb301140514097235a9f2a00a9acb2a) Sponsors: Sync README with website (ESLint Jenkins)
+* [`1f17533`](https://github.com/eslint/eslint/commit/1f175338cba29960aab67a540f516051f9d428c8) Docs: Gitter -> Discord URL (refs #13039) (#13308) (Nicholas C. Zakas)
+* [`82a448a`](https://github.com/eslint/eslint/commit/82a448a7deff24e9207f60dfe77622c00102bd99) Docs: improve documentation of no-return-await (#13215) (Linus Unnebäck)
+* [`742941d`](https://github.com/eslint/eslint/commit/742941d7fdc3fd79ff8c5d2588413e0d3a5a525b) Update: added typescript-eslint/recommended configs for init (#13235) (Anix)
+* [`3d03df0`](https://github.com/eslint/eslint/commit/3d03df08c8000403a85baffe2a000287f3335114) Sponsors: Sync README with website (ESLint Jenkins)
+* [`f44a6b4`](https://github.com/eslint/eslint/commit/f44a6b4fd92602af8e2c75d5852f796ec064aa8e) Chore: fix invalid syntax in require-await tests (#13277) (Milos Djermanovic)
+* [`2c778fb`](https://github.com/eslint/eslint/commit/2c778fb6e31b7943bb27a47a6e15dcbfd8336f39) Fix: remove custom plugins from replacedBy metadata (#13274) (Kai Cataldo)
+* [`0db3b1d`](https://github.com/eslint/eslint/commit/0db3b1d5cc5e4e1de21462679581b7a4d89ff36e) Sponsors: Sync README with website (ESLint Jenkins)
v7.0.0 - May 8, 2020
* [`b98d8bd`](https://github.com/eslint/eslint/commit/b98d8bda4630fe8278c5aa2b6650630770568fe5) Upgrade: eslint-release@2.0.0 (#13271) (Kai Cataldo)
<br />
[![Open Collective Backers](https://img.shields.io/opencollective/backers/eslint)](https://opencollective.com/eslint)
[![Open Collective Sponsors](https://img.shields.io/opencollective/sponsors/eslint)](https://opencollective.com/eslint)
-[![Join the chat at https://gitter.im/eslint/eslint](https://badges.gitter.im/Join%20Chat.svg)](https://gitter.im/eslint/eslint?utm_source=badge&utm_medium=badge&utm_campaign=pr-badge&utm_content=badge)
[![Follow us on Twitter](https://img.shields.io/twitter/follow/geteslint?label=Follow&style=social)](https://twitter.com/intent/user?screen_name=geteslint)
# ESLint
[Code of Conduct](https://js.foundation/community/code-of-conduct) |
[Twitter](https://twitter.com/geteslint) |
[Mailing List](https://groups.google.com/group/eslint) |
-[Chat Room](https://gitter.im/eslint/eslint)
+[Chat Room](https://eslint.org/chat)
ESLint is a tool for identifying and reporting on patterns found in ECMAScript/JavaScript code. In many ways, it is similar to JSLint and JSHint with a few exceptions:
### Where to ask for help?
-Join our [Mailing List](https://groups.google.com/group/eslint) or [Chatroom](https://gitter.im/eslint/eslint).
+Join our [Mailing List](https://groups.google.com/group/eslint) or [Chatroom](https://eslint.org/chat).
## <a name="releases"></a>Releases
<h3>Gold Sponsors</h3>
<p><a href="https://www.shopify.com"><img src="https://images.opencollective.com/shopify/e780cd4/logo.png" alt="Shopify" height="96"></a> <a href="https://www.salesforce.com"><img src="https://images.opencollective.com/salesforce/ca8f997/logo.png" alt="Salesforce" height="96"></a> <a href="https://www.airbnb.com/"><img src="https://images.opencollective.com/airbnb/d327d66/logo.png" alt="Airbnb" height="96"></a></p><h3>Silver Sponsors</h3>
<p><a href="https://www.ampproject.org/"><img src="https://images.opencollective.com/amp/c8a3b25/logo.png" alt="AMP Project" height="64"></a></p><h3>Bronze Sponsors</h3>
-<p><a href="https://www.casinotop.com/"><img src="https://images.opencollective.com/casinotop-com/10fd95b/logo.png" alt="CasinoTop.com" height="32"></a> <a href="https://www.casinotopp.net/"><img src="https://images.opencollective.com/casino-topp/1dd399a/logo.png" alt="Casino Topp" height="32"></a> <a href="https://writersperhour.com/urgent-essay-writing-service"><img src="https://images.opencollective.com/writersperhour/5787d4b/logo.png" alt="Writers Per Hour" height="32"></a> <a href="https://www.crosswordsolver.org/anagram-solver/"><img src="https://images.opencollective.com/anagram-solver/2666271/logo.png" alt="Anagram Solver" height="32"></a> <a href="https://cooltechzone.com/netflix-vpn"><img src="https://images.opencollective.com/vpn-netflix/4850160/logo.png" alt="vpn netflix" height="32"></a> <a href="https://www.kasinot.fi"><img src="https://images.opencollective.com/kasinot-fi/e09aa2e/logo.png" alt="Kasinot.fi" height="32"></a> <a href="https://www.pelisivut.com"><img src="https://images.opencollective.com/pelisivut/04f08f2/logo.png" alt="Pelisivut" height="32"></a> <a href="https://www.nettikasinot.org"><img src="https://images.opencollective.com/nettikasinot-org/bbd887f/logo.png" alt="Nettikasinot.org" height="32"></a> <a href="https://www.bonus.com.de/freispiele"><img src="https://images.opencollective.com/bonusfinder-deutschland/646169e/logo.png" alt="BonusFinder Deutschland" height="32"></a> <a href="https://medium.com/@niksundin/best-web-design-companies-1872e445775f"><img src="https://images.opencollective.com/top-web-design-agencies/d92d747/logo.png" alt="Top Web Design Agencies" height="32"></a> <a href="https://www.bugsnag.com/platforms?utm_source=Open Collective&utm_medium=Website&utm_content=open-source&utm_campaign=2019-community&utm_term="><img src="https://images.opencollective.com/bugsnag-stability-monitoring/c2cef36/logo.png" alt="Bugsnag Stability Monitoring" height="32"></a> <a href="https://mixpanel.com"><img src="https://images.opencollective.com/mixpanel/cd682f7/logo.png" alt="Mixpanel" height="32"></a> <a href="https://www.vpsserver.com"><img src="https://images.opencollective.com/vpsservercom/logo.png" alt="VPS Server" height="32"></a> <a href="https://icons8.com"><img src="https://images.opencollective.com/icons8/0b37d14/logo.png" alt="Free Icons by Icons8" height="32"></a> <a href="https://uxplanet.org/top-ui-ux-design-agencies-user-experience-firms-8c54697e290"><img src="https://images.opencollective.com/ui-ux-design-agencies/cae5dfe/logo.png" alt="UI UX Design Agencies" height="32"></a> <a href="https://clay.global"><img src="https://images.opencollective.com/clayglobal/2468f34/logo.png" alt="clay" height="32"></a> <a href="https://discordapp.com"><img src="https://images.opencollective.com/discordapp/7e3d9a9/logo.png" alt="Discord" height="32"></a> <a href="https://themeisle.com"><img src="https://images.opencollective.com/themeisle/d5592fe/logo.png" alt="ThemeIsle" height="32"></a> <a href="https://tekhattan.com"><img src="https://images.opencollective.com/tekhattan/bc73c28/logo.png" alt="TekHattan" height="32"></a> <a href="https://www.marfeel.com/"><img src="https://images.opencollective.com/marfeel/4b88e30/logo.png" alt="Marfeel" height="32"></a> <a href="http://www.firesticktricks.com"><img src="https://images.opencollective.com/fire-stick-tricks/b8fbe2c/logo.png" alt="Fire Stick Tricks" height="32"></a></p>
+<p><a href="https://bruce.agency"><img src="https://images.opencollective.com/brucemade/0c70c59/logo.png" alt="Bruce" height="32"></a> <a href="https://edubirdie.com/"><img src="https://images.opencollective.com/edubirdie2/b1d51ab/logo.png" alt="EduBirdie" height="32"></a> <a href="https://www.casinotop.com/"><img src="https://images.opencollective.com/casinotop-com/10fd95b/logo.png" alt="CasinoTop.com" height="32"></a> <a href="https://www.casinotopp.net/"><img src="https://images.opencollective.com/casino-topp/1dd399a/logo.png" alt="Casino Topp" height="32"></a> <a href="https://writersperhour.com/urgent-essay-writing-service"><img src="https://images.opencollective.com/writersperhour/5787d4b/logo.png" alt="Writers Per Hour" height="32"></a> <a href="https://www.crosswordsolver.org/anagram-solver/"><img src="https://images.opencollective.com/anagram-solver/2666271/logo.png" alt="Anagram Solver" height="32"></a> <a href="https://cooltechzone.com/netflix-vpn"><img src="https://images.opencollective.com/vpn-netflix/4850160/logo.png" alt="vpn netflix" height="32"></a> <a href="https://www.kasinot.fi"><img src="https://images.opencollective.com/kasinot-fi/e09aa2e/logo.png" alt="Kasinot.fi" height="32"></a> <a href="https://www.pelisivut.com"><img src="https://images.opencollective.com/pelisivut/04f08f2/logo.png" alt="Pelisivut" height="32"></a> <a href="https://www.nettikasinot.org"><img src="https://images.opencollective.com/nettikasinot-org/bbd887f/logo.png" alt="Nettikasinot.org" height="32"></a> <a href="https://www.bonus.com.de/freispiele"><img src="https://images.opencollective.com/bonusfinder-deutschland/646169e/logo.png" alt="BonusFinder Deutschland" height="32"></a> <a href="https://www.bugsnag.com/platforms?utm_source=Open Collective&utm_medium=Website&utm_content=open-source&utm_campaign=2019-community&utm_term="><img src="https://images.opencollective.com/bugsnag-stability-monitoring/c2cef36/logo.png" alt="Bugsnag Stability Monitoring" height="32"></a> <a href="https://mixpanel.com"><img src="https://images.opencollective.com/mixpanel/cd682f7/logo.png" alt="Mixpanel" height="32"></a> <a href="https://www.vpsserver.com"><img src="https://images.opencollective.com/vpsservercom/logo.png" alt="VPS Server" height="32"></a> <a href="https://icons8.com"><img src="https://images.opencollective.com/icons8/0b37d14/logo.png" alt="Free Icons by Icons8" height="32"></a> <a href="https://discordapp.com"><img src="https://images.opencollective.com/discordapp/7e3d9a9/logo.png" alt="Discord" height="32"></a> <a href="https://themeisle.com"><img src="https://images.opencollective.com/themeisle/d5592fe/logo.png" alt="ThemeIsle" height="32"></a> <a href="https://tekhattan.com"><img src="https://images.opencollective.com/tekhattan/bc73c28/logo.png" alt="TekHattan" height="32"></a> <a href="https://www.marfeel.com/"><img src="https://images.opencollective.com/marfeel/4b88e30/logo.png" alt="Marfeel" height="32"></a> <a href="http://www.firesticktricks.com"><img src="https://images.opencollective.com/fire-stick-tricks/b8fbe2c/logo.png" alt="Fire Stick Tricks" height="32"></a></p>
<!--sponsorsend-->
## <a name="technology-sponsors"></a>Technology Sponsors
-If you have a question about how to use ESLint, please ask it in our [Gitter channel](https://gitter.im/eslint/eslint).
+If you have a question about how to use ESLint, please ask it in our [chatroom](https://eslint.org/chat).
Please include as much detail as possible to help us properly address your issue. If we need to triage issues and constantly ask people for more detail, that's time taken away from actually fixing issues. Help us be as efficient as possible by including a lot of detail in your issues.
-**Note:** If you just have a question that won't necessarily result in a change to ESLint, such as asking how something works or how to contribute, please use the [mailing list](https://groups.google.com/group/eslint) or [chat](https://gitter.im/eslint/eslint) instead of filing an issue.
+**Note:** If you just have a question that won't necessarily result in a change to ESLint, such as asking how something works or how to contribute, please use the [mailing list](https://groups.google.com/group/eslint) or [chat](https://eslint.org/chat) instead of filing an issue.
ESLint is all about rules. For most of the project's lifetime, we've had over 200 rules, and that list continues to grow. However, we can't just accept any proposed rule because all rules need to work cohesively together. As such, we have some guidelines around which rules can be part of the ESLint core and which are better off as custom rules and plugins.
-**Note:** As of 2016, we accept only rules that are deemed extremely important for inclusion. We prefer that new rules be implemented in plugins.
+**Note:** As of 2020, we only accept rules related to new ECMAScript features. We prefer that new rules be implemented in plugins.
## Core Rule Guidelines
1. Fulfill all the criteria listed in the "Core Rule Guidelines" section
1. Have an ESLint team member champion inclusion of the rule
-1. Be very important for ESLint users because it either catches a serious problem or allows styling of code in accordance with a popular style guide
+1. Be related to an ECMAScript feature that has reached stage 4 in the preceding 12 months
Keep in mind that we have over 200 rules, and that is daunting both for end users and the ESLint team (who has to maintain them). As such, any new rules must be deemed of high importance to be considered for inclusion in ESLint.
Please include as much detail as possible to help us properly address your issue. If we need to triage issues and constantly ask people for more detail, that's time taken away from actually fixing issues. Help us be as efficient as possible by including a lot of detail in your issues.
-**Note:** If you just have a question that won't necessarily result in a change to ESLint, such as asking how something works or how to contribute, please use the [mailing list](https://groups.google.com/group/eslint) or [chat](https://gitter.im/eslint/eslint) instead of filing an issue.
+**Note:** If you just have a question that won't necessarily result in a change to ESLint, such as asking how something works or how to contribute, please use the [mailing list](https://groups.google.com/group/eslint) or [chat](https://eslint.org/chat) instead of filing an issue.
---
-[configuration object]: ../user-guide/configuring.md
+[configuration object]: ../user-guide/configuring
[builtin-formatters]: https://eslint.org/docs/user-guide/formatters/
[thirdparty-formatters]: https://www.npmjs.com/search?q=eslintformatter
[eslint]: #eslint-class
1. Send email congratulating the new committer and confirming that they would like to accept. This should also outline the responsibilities of a committer with a link to the maintainer guide.
1. Add the GitHub user to the "ESLint Team" team
1. Add committer email to the ESLint team mailing list
-1. Invite to Gitter team chatroom
+1. Invite to Discord team channel
1. Tweet congratulations to the new committer from the ESLint Twitter account
### Reviewers
1. Add the GitHub user to the "ESLint TSC" GitHub team
1. Set the GitHub user to be have the "Owner" role for the ESLint organization
1. Send a welcome email with a link to the [maintainer guide](./) and the [npm 2FA guide](./npm-2fa).
-1. Invite to the Gitter TSC chatroom
+1. Invite to the Discord TSC channel
1. Make the TSC member an admin on the ESLint team mailing list
1. Add the TSC member to the recurring TSC meeting event on Google Calendar
1. Add the TSC member as an admin to ESLint Twitter Account on Tweetdeck
#### TSC Meetings
-The TSC meets every other week in the [TSC Meeting](https://gitter.im/eslint/tsc-meetings) chatroom. The meeting is run by
-a designated moderator approved by the TSC.
+The TSC meets every other week in the TSC Meeting [Discord](https://eslint.org/chat) channel. The meeting is run by a designated moderator approved by the TSC.
Items are added to the TSC agenda which are considered contentious or
are modifications of governance, contribution policy, TSC membership,
a.then((foo) => {});
a.then((foo) => a);
a((foo) => { if (true) {} });
+const f = /** @type {number} */(a) => a + a;
+const g = /* comment */ (a) => a + a;
+const h = (a) /* comment */ => a + a;
```
Examples of **correct** code for this rule with the `"as-needed"` option:
(a = 10) => a;
([a, b]) => a;
({a, b}) => a;
+const f = (/** @type {number} */a) => a + a;
+const g = (/* comment */ a) => a + a;
+const h = (a /* comment */) => a + a;
```
### requireForBlockBody
(function(){
var x = 0;
}());
+
+(() => {
+ var x = 0;
+})();
```
Examples of **correct** code for this rule with the `{ "IIFEs": true }` option:
(function(){
var x = 0;
}());
+
+(() => {
+ var x = 0;
+})();
```
## When Not To Use It
/*eslint no-array-constructor: "error"*/
Array(0, 1, 2)
-```
-
-```js
-/*eslint no-array-constructor: "error"*/
new Array(0, 1, 2)
```
/*eslint no-array-constructor: "error"*/
Array(500)
-```
-
-```js
-/*eslint no-array-constructor: "error"*/
new Array(someOtherArray.length)
+
+[0, 1, 2]
```
## When Not To Use It
--- /dev/null
+# Disallow Number Literals That Lose Precision (no-loss-of-precision)
+
+This rule would disallow the use of number literals that immediately lose precision at runtime when converted to a JS `Number` due to 64-bit floating-point rounding.
+
+## Rule Details
+
+In JS, `Number`s are stored as double-precision floating-point numbers according to the [IEEE 754 standard](https://en.wikipedia.org/wiki/IEEE_754). Because of this, numbers can only retain accuracy up to a certain amount of digits. If the programmer enters additional digits, those digits will be lost in the conversion to the `Number` type and will result in unexpected behavior.
+
+Examples of **incorrect** code for this rule:
+
+```js
+/*eslint no-loss-of-precision: "error"*/
+
+const x = 9007199254740993
+const x = 5123000000000000000000000000001
+const x = 1230000000000000000000000.0
+const x = .1230000000000000000000000
+const x = 0X20000000000001
+```
+
+Examples of **correct** code for this rule:
+
+```js
+/*eslint no-loss-of-precision: "error"*/
+
+const x = 12345
+const x = 123.456
+const x = 123e34
+const x = 12300000000000000000000000
+const x = 0x1FFFFFFFFFFFFF
+const x = 9007199254740991
+```
# Disallows unnecessary `return await` (no-return-await)
-Inside an `async function`, `return await` is seldom useful. Since the return value of an `async function` is always wrapped in `Promise.resolve`, `return await` doesn’t actually do anything except add extra time before the overarching Promise resolves or rejects. The only valid exception is if `return await` is used in a try/catch statement to catch errors from another Promise-based function.
+Using `return await` inside an `async function` keeps the current function in the call stack until the Promise that is being awaited has resolved, at the cost of an extra microtask before resolving the outer Promise. `return await` can also be used in a try/catch statement to catch errors from another function that returns a Promise.
+
+You can avoid the extra microtask by not awaiting the return value, with the trade off of the function no longer being a part of the stack trace if an error is thrown asynchronously from the Promise being returned. This can make debugging more difficult.
## Rule Details
## When Not To Use It
-If you want to use `await` to denote a value that is a thenable, even when it is not necessary; or if you do not want the performance benefit of avoiding `return await`, you can turn off this rule.
+There are a few reasons you might want to turn this rule off:
+
+- If you want to use `await` to denote a value that is a thenable
+- If you do not want the performance benefit of avoiding `return await`
+- If you want the functions to show up in stack traces (useful for debugging purposes)
## Further Reading
}
if (answers.typescript && config.extends.includes("eslint:recommended")) {
config.extends.push("plugin:@typescript-eslint/eslint-recommended");
+ config.extends.push("plugin:@typescript-eslint/recommended");
}
// normalize extends
});
});
- const eventGenerator = new CodePathAnalyzer(new NodeEventGenerator(emitter));
+ // only run code path analyzer if the top level node is "Program", skip otherwise
+ const eventGenerator = nodeQueue[0].node.type === "Program" ? new CodePathAnalyzer(new NodeEventGenerator(emitter)) : new NodeEventGenerator(emitter);
nodeQueue.forEach(traversalInfo => {
currentNode = traversalInfo.node;
/**
- * @fileoverview Rule to flag wrapping non-iife in parens
+ * @fileoverview Rule to enforce getter and setter pairs in objects and classes.
* @author Gyandeep Singh
*/
], `${shouldAddSpaceForAsync ? " " : ""}${paramToken.value}`);
}
+ /**
+ * Checks whether there are comments inside the params or not.
+ * @returns {boolean} `true` if there are comments inside of parens, else `false`
+ */
+ function hasCommentsInParens() {
+ if (astUtils.isOpeningParenToken(firstTokenOfParam)) {
+ const closingParenToken = sourceCode.getTokenAfter(node.params[0], astUtils.isClosingParenToken);
+
+ return closingParenToken && sourceCode.commentsExistBetween(firstTokenOfParam, closingParenToken);
+ }
+ return false;
+
+ }
+
+ if (hasCommentsInParens()) {
+ return;
+ }
+
// "as-needed", { "requireForBlockBody": true }: x => x
if (
requireForBlockBody &&
- node.params.length === 1 &&
node.params[0].type === "Identifier" &&
!node.params[0].typeAnnotation &&
node.body.type !== "BlockStatement" &&
// "as-needed": x => x
if (asNeeded &&
- node.params.length === 1 &&
node.params[0].type === "Identifier" &&
!node.params[0].typeAnnotation &&
!node.returnType
}
return {
- ArrowFunctionExpression: parens
+ "ArrowFunctionExpression[params.length=1]": parens
};
}
};
// Check.
if (!isValid(openBrace, firstToken)) {
+ let loc = openBrace.loc;
+
+ if (messageId === "extra") {
+ loc = {
+ start: openBrace.loc.end,
+ end: firstToken.loc.start
+ };
+ }
+
context.report({
node,
- loc: openBrace.loc.start,
+ loc,
messageId,
data: {
location: "after",
});
}
if (!isValid(lastToken, closeBrace)) {
+ let loc = closeBrace.loc;
+
+ if (messageId === "extra") {
+ loc = {
+ start: lastToken.loc.end,
+ end: closeBrace.loc.start
+ };
+ }
context.report({
node,
- loc: closeBrace.loc.start,
+ loc,
messageId,
data: {
location: "before",
meta: {
deprecated: true,
- replacedBy: ["node/callback-return"],
+ replacedBy: [],
type: "suggestion",
meta: {
deprecated: true,
- replacedBy: ["node/global-require"],
+ replacedBy: [],
type: "suggestion",
meta: {
deprecated: true,
- replacedBy: ["node/handle-callback-err"],
+ replacedBy: [],
type: "suggestion",
"no-lone-blocks": () => require("./no-lone-blocks"),
"no-lonely-if": () => require("./no-lonely-if"),
"no-loop-func": () => require("./no-loop-func"),
+ "no-loss-of-precision": () => require("./no-loss-of-precision"),
"no-magic-numbers": () => require("./no-magic-numbers"),
"no-misleading-character-class": () => require("./no-misleading-character-class"),
"no-mixed-operators": () => require("./no-mixed-operators"),
context.report({
node,
loc: {
- line: i,
- column: sourceCode.lines[i - 1].length
+ start: {
+ line: i,
+ column: sourceCode.lines[i - 1].length
+ },
+ end: {
+ line: i + 1,
+ column: 0
+ }
},
messageId: expectedLF ? "expectedLF" : "expectedCRLF",
fix: createFix(range, expectedLFChars)
* @returns {boolean} True if it's an IIFE
*/
function isIIFE(node) {
- return node.type === "FunctionExpression" && node.parent && node.parent.type === "CallExpression" && node.parent.callee === node;
+ return (node.type === "FunctionExpression" || node.type === "ArrowFunctionExpression") && node.parent && node.parent.type === "CallExpression" && node.parent.callee === node;
}
/**
meta: {
deprecated: true,
- replacedBy: ["node/no-deprecated-api"],
+ replacedBy: [],
type: "problem",
--- /dev/null
+/**
+ * @fileoverview Rule to flag numbers that will lose significant figure precision at runtime
+ * @author Jacob Moore
+ */
+
+"use strict";
+
+//------------------------------------------------------------------------------
+// Rule Definition
+//------------------------------------------------------------------------------
+
+module.exports = {
+ meta: {
+ type: "problem",
+
+ docs: {
+ description: "disallow literal numbers that lose precision",
+ category: "Possible Errors",
+ recommended: false,
+ url: "https://eslint.org/docs/rules/no-loss-of-precision"
+ },
+ schema: [],
+ messages: {
+ noLossOfPrecision: "This number literal will lose precision at runtime."
+ }
+ },
+
+ create(context) {
+
+ /**
+ * Returns whether the node is number literal
+ * @param {Node} node the node literal being evaluated
+ * @returns {boolean} true if the node is a number literal
+ */
+ function isNumber(node) {
+ return typeof node.value === "number";
+ }
+
+
+ /**
+ * Checks whether the number is base ten
+ * @param {ASTNode} node the node being evaluated
+ * @returns {boolean} true if the node is in base ten
+ */
+ function isBaseTen(node) {
+ const prefixes = ["0x", "0X", "0b", "0B", "0o", "0O"];
+
+ return prefixes.every(prefix => !node.raw.startsWith(prefix)) &&
+ !/^0[0-7]+$/u.test(node.raw);
+ }
+
+ /**
+ * Checks that the user-intended non-base ten number equals the actual number after is has been converted to the Number type
+ * @param {Node} node the node being evaluated
+ * @returns {boolean} true if they do not match
+ */
+ function notBaseTenLosesPrecision(node) {
+ const rawString = node.raw.toUpperCase();
+ let base = 0;
+
+ if (rawString.startsWith("0B")) {
+ base = 2;
+ } else if (rawString.startsWith("0X")) {
+ base = 16;
+ } else {
+ base = 8;
+ }
+
+ return !rawString.endsWith(node.value.toString(base).toUpperCase());
+ }
+
+ /**
+ * Adds a decimal point to the numeric string at index 1
+ * @param {string} stringNumber the numeric string without any decimal point
+ * @returns {string} the numeric string with a decimal point in the proper place
+ */
+ function addDecimalPointToNumber(stringNumber) {
+ return `${stringNumber.slice(0, 1)}.${stringNumber.slice(1)}`;
+ }
+
+ /**
+ * Returns the number stripped of leading zeros
+ * @param {string} numberAsString the string representation of the number
+ * @returns {string} the stripped string
+ */
+ function removeLeadingZeros(numberAsString) {
+ return numberAsString.replace(/^0*/u, "");
+ }
+
+ /**
+ * Returns the number stripped of trailing zeros
+ * @param {string} numberAsString the string representation of the number
+ * @returns {string} the stripped string
+ */
+ function removeTrailingZeros(numberAsString) {
+ return numberAsString.replace(/0*$/u, "");
+ }
+
+ /**
+ * Converts an integer to to an object containing the the integer's coefficient and order of magnitude
+ * @param {string} stringInteger the string representation of the integer being converted
+ * @returns {Object} the object containing the the integer's coefficient and order of magnitude
+ */
+ function normalizeInteger(stringInteger) {
+ const significantDigits = removeTrailingZeros(removeLeadingZeros(stringInteger));
+
+ return {
+ magnitude: stringInteger.startsWith("0") ? stringInteger.length - 2 : stringInteger.length - 1,
+ coefficient: addDecimalPointToNumber(significantDigits)
+ };
+ }
+
+ /**
+ *
+ * Converts a float to to an object containing the the floats's coefficient and order of magnitude
+ * @param {string} stringFloat the string representation of the float being converted
+ * @returns {Object} the object containing the the integer's coefficient and order of magnitude
+ */
+ function normalizeFloat(stringFloat) {
+ const trimmedFloat = removeLeadingZeros(stringFloat);
+
+ if (trimmedFloat.startsWith(".")) {
+ const decimalDigits = trimmedFloat.split(".").pop();
+ const significantDigits = removeLeadingZeros(decimalDigits);
+
+ return {
+ magnitude: significantDigits.length - decimalDigits.length - 1,
+ coefficient: addDecimalPointToNumber(significantDigits)
+ };
+
+ }
+ return {
+ magnitude: trimmedFloat.indexOf(".") - 1,
+ coefficient: addDecimalPointToNumber(trimmedFloat.replace(".", ""))
+
+ };
+ }
+
+
+ /**
+ * Converts a base ten number to proper scientific notation
+ * @param {string} stringNumber the string representation of the base ten number to be converted
+ * @returns {string} the number converted to scientific notation
+ */
+ function convertNumberToScientificNotation(stringNumber) {
+ const splitNumber = stringNumber.replace("E", "e").split("e");
+ const originalCoefficient = splitNumber[0];
+ const normalizedNumber = stringNumber.includes(".") ? normalizeFloat(originalCoefficient)
+ : normalizeInteger(originalCoefficient);
+ const normalizedCoefficient = normalizedNumber.coefficient;
+ const magnitude = splitNumber.length > 1 ? (parseInt(splitNumber[1], 10) + normalizedNumber.magnitude)
+ : normalizedNumber.magnitude;
+
+ return `${normalizedCoefficient}e${magnitude}`;
+
+ }
+
+ /**
+ * Checks that the user-intended base ten number equals the actual number after is has been converted to the Number type
+ * @param {Node} node the node being evaluated
+ * @returns {boolean} true if they do not match
+ */
+ function baseTenLosesPrecision(node) {
+ const normalizedRawNumber = convertNumberToScientificNotation(node.raw);
+ const requestedPrecision = normalizedRawNumber.split("e")[0].replace(".", "").length;
+
+ if (requestedPrecision > 100) {
+ return true;
+ }
+ const storedNumber = node.value.toPrecision(requestedPrecision);
+ const normalizedStoredNumber = convertNumberToScientificNotation(storedNumber);
+
+ return normalizedRawNumber !== normalizedStoredNumber;
+ }
+
+
+ /**
+ * Checks that the user-intended number equals the actual number after is has been converted to the Number type
+ * @param {Node} node the node being evaluated
+ * @returns {boolean} true if they do not match
+ */
+ function losesPrecision(node) {
+ return isBaseTen(node) ? baseTenLosesPrecision(node) : notBaseTenLosesPrecision(node);
+ }
+
+
+ return {
+ Literal(node) {
+ if (node.value && isNumber(node) && losesPrecision(node)) {
+ context.report({
+ messageId: "noLossOfPrecision",
+ node
+ });
+ }
+ }
+ };
+ }
+};
meta: {
deprecated: true,
- replacedBy: ["node/no-mixed-requires"],
+ replacedBy: [],
type: "suggestion",
create(context) {
- //--------------------------------------------------------------------------
- // Helpers
- //--------------------------------------------------------------------------
-
- /**
- * Reports a node.
- * @param {ASTNode} node The node to report
- * @returns {void}
- * @private
- */
- function report(node) {
- context.report({
- node,
- messageId: "noFunctionConstructor"
- });
- }
-
return {
- "NewExpression[callee.name = 'Function']": report,
- "CallExpression[callee.name = 'Function']": report
+ "Program:exit"() {
+ const globalScope = context.getScope();
+ const variable = globalScope.set.get("Function");
+
+ if (variable && variable.defs.length === 0) {
+ variable.references.forEach(ref => {
+ const node = ref.identifier;
+ const { parent } = node;
+
+ if (
+ parent &&
+ (parent.type === "NewExpression" || parent.type === "CallExpression") &&
+ node === parent.callee
+ ) {
+ context.report({
+ node: parent,
+ messageId: "noFunctionConstructor"
+ });
+ }
+ });
+ }
+ }
};
}
meta: {
deprecated: true,
- replacedBy: ["node/no-new-require"],
+ replacedBy: [],
type: "suggestion",
if (variable && variable.defs.length === 0) {
variable.references.forEach(ref => {
const node = ref.identifier;
+ const parent = node.parent;
- if (node.parent && node.parent.type === "NewExpression") {
+ if (parent && parent.type === "NewExpression" && parent.callee === node) {
context.report({
node,
messageId: "noNewSymbol"
meta: {
deprecated: true,
- replacedBy: ["node/no-path-concat"],
+ replacedBy: [],
type: "suggestion",
meta: {
deprecated: true,
- replacedBy: ["node/no-process-env"],
+ replacedBy: [],
type: "suggestion",
meta: {
deprecated: true,
- replacedBy: ["node/no-process-exit"],
+ replacedBy: [],
type: "suggestion",
meta: {
deprecated: true,
- replacedBy: ["node/no-restricted-require"],
+ replacedBy: [],
type: "suggestion",
meta: {
deprecated: true,
- replacedBy: ["node/no-sync"],
+ replacedBy: [],
type: "suggestion",
context.report({
node,
messageId: "expectVarOnNewline",
- loc: current.loc.start,
+ loc: current.loc,
fix: fixer => fixer.insertTextBefore(current, "\n")
});
}
}
if (requirePaddingFor(node)) {
+
if (!blockHasTopPadding) {
context.report({
node,
- loc: { line: tokenBeforeFirst.loc.start.line, column: tokenBeforeFirst.loc.start.column },
+ loc: {
+ start: tokenBeforeFirst.loc.start,
+ end: firstBlockToken.loc.start
+ },
fix(fixer) {
return fixer.insertTextAfter(tokenBeforeFirst, "\n");
},
if (!blockHasBottomPadding) {
context.report({
node,
- loc: { line: tokenAfterLast.loc.end.line, column: tokenAfterLast.loc.end.column - 1 },
+ loc: {
+ end: tokenAfterLast.loc.start,
+ start: lastBlockToken.loc.end
+ },
fix(fixer) {
return fixer.insertTextBefore(tokenAfterLast, "\n");
},
context.report({
node,
- loc: { line: tokenBeforeFirst.loc.start.line, column: tokenBeforeFirst.loc.start.column },
+ loc: {
+ start: tokenBeforeFirst.loc.start,
+ end: firstBlockToken.loc.start
+ },
fix(fixer) {
return fixer.replaceTextRange([tokenBeforeFirst.range[1], firstBlockToken.range[0] - firstBlockToken.loc.start.column], "\n");
},
context.report({
node,
- loc: { line: tokenAfterLast.loc.end.line, column: tokenAfterLast.loc.end.column - 1 },
+ loc: {
+ end: tokenAfterLast.loc.start,
+ start: lastBlockToken.loc.end
+ },
messageId: "neverPadBlock",
fix(fixer) {
return fixer.replaceTextRange([lastBlockToken.range[1], tokenAfterLast.range[0] - tokenAfterLast.loc.start.column], "\n");
if (alwaysSpace && !hasWhitespace) {
context.report({
node,
- loc: {
- line: operator.loc.end.line,
- column: operator.loc.end.column
- },
+ loc: operator.loc,
messageId: "expectedWhitespace",
data: {
type
context.report({
node,
loc: {
- line: operator.loc.end.line,
- column: operator.loc.end.column
+ start: operator.loc.end,
+ end: nextToken.loc.start
},
messageId: "unexpectedWhitespace",
data: {
}
/**
+ * Report location example :
+ *
+ * for unexpected space `before`
+ *
+ * var a = 'b' ;
+ * ^^^
+ *
+ * for unexpected space `after`
+ *
+ * var a = 'b'; c = 10;
+ * ^^
+ *
* Reports if the given token has invalid spacing.
* @param {Token} token The semicolon token to check.
* @param {ASTNode} node The corresponding node of the token.
*/
function checkSemicolonSpacing(token, node) {
if (astUtils.isSemicolonToken(token)) {
- const location = token.loc.start;
-
if (hasLeadingSpace(token)) {
if (!requireSpaceBefore) {
+ const tokenBefore = sourceCode.getTokenBefore(token);
+ const loc = {
+ start: tokenBefore.loc.end,
+ end: token.loc.start
+ };
+
context.report({
node,
- loc: location,
+ loc,
messageId: "unexpectedWhitespaceBefore",
fix(fixer) {
- const tokenBefore = sourceCode.getTokenBefore(token);
return fixer.removeRange([tokenBefore.range[1], token.range[0]]);
}
}
} else {
if (requireSpaceBefore) {
+ const loc = token.loc;
+
context.report({
node,
- loc: location,
+ loc,
messageId: "missingWhitespaceBefore",
fix(fixer) {
return fixer.insertTextBefore(token, " ");
if (!isFirstTokenInCurrentLine(token) && !isLastTokenInCurrentLine(token) && !isBeforeClosingParen(token)) {
if (hasTrailingSpace(token)) {
if (!requireSpaceAfter) {
+ const tokenAfter = sourceCode.getTokenAfter(token);
+ const loc = {
+ start: token.loc.end,
+ end: tokenAfter.loc.start
+ };
+
context.report({
node,
- loc: location,
+ loc,
messageId: "unexpectedWhitespaceAfter",
fix(fixer) {
- const tokenAfter = sourceCode.getTokenAfter(token);
return fixer.removeRange([token.range[1], tokenAfter.range[0]]);
}
}
} else {
if (requireSpaceAfter) {
+ const loc = token.loc;
+
context.report({
node,
- loc: location,
+ loc,
messageId: "missingWhitespaceAfter",
fix(fixer) {
return fixer.insertTextAfter(token, " ");
/**
* Gets next location when the result is not out of bound, otherwise returns null.
+ *
+ * Assumptions:
+ *
+ * - The given location represents a valid location in the given source code.
+ * - Columns are 0-based.
+ * - Lines are 1-based.
+ * - Column immediately after the last character in a line (not incl. linebreaks) is considered to be a valid location.
+ * - If the source code ends with a linebreak, `sourceCode.lines` array will have an extra element (empty string) at the end.
+ * The start (column 0) of that extra line is considered to be a valid location.
+ *
+ * Examples of successive locations (line, column):
+ *
+ * code: foo
+ * locations: (1, 0) -> (1, 1) -> (1, 2) -> (1, 3) -> null
+ *
+ * code: foo<LF>
+ * locations: (1, 0) -> (1, 1) -> (1, 2) -> (1, 3) -> (2, 0) -> null
+ *
+ * code: foo<CR><LF>
+ * locations: (1, 0) -> (1, 1) -> (1, 2) -> (1, 3) -> (2, 0) -> null
+ *
+ * code: a<LF>b
+ * locations: (1, 0) -> (1, 1) -> (2, 0) -> (2, 1) -> null
+ *
+ * code: a<LF>b<LF>
+ * locations: (1, 0) -> (1, 1) -> (2, 0) -> (2, 1) -> (3, 0) -> null
+ *
+ * code: a<CR><LF>b<CR><LF>
+ * locations: (1, 0) -> (1, 1) -> (2, 0) -> (2, 1) -> (3, 0) -> null
+ *
+ * code: a<LF><LF>
+ * locations: (1, 0) -> (1, 1) -> (2, 0) -> (3, 0) -> null
+ *
+ * code: <LF>
+ * locations: (1, 0) -> (2, 0) -> null
+ *
+ * code:
+ * locations: (1, 0) -> null
* @param {SourceCode} sourceCode The sourceCode
* @param {{line: number, column: number}} location The location
* @returns {{line: number, column: number} | null} Next location
*/
- getNextLocation(sourceCode, location) {
- const index = sourceCode.getIndexFromLoc(location);
+ getNextLocation(sourceCode, { line, column }) {
+ if (column < sourceCode.lines[line - 1].length) {
+ return {
+ line,
+ column: column + 1
+ };
+ }
- // Avoid out of bound location
- if (index + 1 > sourceCode.text.length) {
- return null;
+ if (line < sourceCode.lines.length) {
+ return {
+ line: line + 1,
+ column: 0
+ };
}
- return sourceCode.getLocFromIndex(index + 1);
+ return null;
},
/**
* @returns {Object} An object containing a leading and trailing array
* of comments indexed by their position.
* @public
+ * @deprecated replaced by getCommentsBefore(), getCommentsAfter(), and getCommentsInside().
*/
getComments(node) {
if (this._commentCache.has(node)) {
The config "<%- configName %>" was referenced from the config file in "<%- importerName %>".
-If you still have problems, please stop by https://gitter.im/eslint/eslint to chat with the team.
+If you still have problems, please stop by https://eslint.org/chat to chat with the team.
ESLint looked for configuration files in <%= directoryPath %> and its ancestors. If it found none, it then looked in your home directory.
-If you think you already have a configuration file or if you need more help, please stop by the ESLint chat room: https://gitter.im/eslint/eslint
+If you think you already have a configuration file or if you need more help, please stop by the ESLint chat room: https://eslint.org/chat
Please remove the "plugins" setting from either config or remove either plugin installation.
-If you still can't figure out the problem, please stop by https://gitter.im/eslint/eslint to chat with the team.
+If you still can't figure out the problem, please stop by https://eslint.org/chat to chat with the team.
The plugin "<%- pluginName %>" was referenced from the config file in "<%- importerName %>".
-If you still can't figure out the problem, please stop by https://gitter.im/eslint/eslint to chat with the team.
+If you still can't figure out the problem, please stop by https://eslint.org/chat to chat with the team.
ESLint couldn't find the plugin "<%- pluginName %>". because there is whitespace in the name. Please check your configuration and remove all whitespace from the plugin name.
-If you still can't figure out the problem, please stop by https://gitter.im/eslint/eslint to chat with the team.
+If you still can't figure out the problem, please stop by https://eslint.org/chat to chat with the team.
{
"name": "eslint",
- "version": "7.0.0",
+ "version": "7.1.0",
"author": "Nicholas C. Zakas <nicholas+npm@nczconsulting.com>",
"description": "An AST-based pattern checker for JavaScript.",
"bin": {
noLineError: require("./no-line-error"),
enhancedParser2: require("./enhanced-parser2"),
enhancedParser3: require("./enhanced-parser3"),
- throwsWithOptions: require("./throws-with-options")
+ throwsWithOptions: require("./throws-with-options"),
+ nonJSParser: require('./non-js-parser')
};
--- /dev/null
+/**
+ * Source code:
+ * function foo(a: number=0): Foo { }
+ */
+
+exports.parseForESLint = () => ({
+ ast: {
+ "kind": "Document",
+ "definitions": [
+ {
+ "kind": "ObjectTypeExtension",
+ "name": {
+ "kind": "Name",
+ "value": "Query",
+ "loc": {
+ "start": 12,
+ "end": 17
+ },
+ "type": "Name"
+ },
+ "interfaces": [],
+ "directives": [],
+ "fields": [
+ {
+ "kind": "FieldDefinition",
+ "name": {
+ "kind": "Name",
+ "value": "login",
+ "loc": {
+ "start": 24,
+ "end": 29
+ },
+ "type": "Name"
+ },
+ "arguments": [
+ {
+ "kind": "InputValueDefinition",
+ "name": {
+ "kind": "Name",
+ "value": "input",
+ "loc": {
+ "start": 30,
+ "end": 35
+ },
+ "type": "Name"
+ },
+ "type": "InputValueDefinition",
+ "directives": [],
+ "loc": {
+ "start": 30,
+ "end": 49
+ },
+ "fieldType": {
+ "kind": "NonNullType",
+ "type": "NonNullType",
+ "loc": {
+ "start": 37,
+ "end": 49
+ },
+ "fieldType": {
+ "kind": "NamedType",
+ "name": {
+ "kind": "Name",
+ "value": "Credentials",
+ "loc": {
+ "start": 37,
+ "end": 48
+ },
+ "type": "Name"
+ },
+ "loc": {
+ "start": 37,
+ "end": 48
+ },
+ "type": "NamedType"
+ }
+ }
+ }
+ ],
+ "type": "FieldDefinition",
+ "directives": [],
+ "loc": {
+ "start": 24,
+ "end": 63
+ },
+ "fieldType": {
+ "kind": "NamedType",
+ "name": {
+ "kind": "Name",
+ "value": "UserProfile",
+ "loc": {
+ "start": 52,
+ "end": 63
+ },
+ "type": "Name"
+ },
+ "loc": {
+ "start": 52,
+ "end": 63
+ },
+ "type": "NamedType"
+ }
+ }
+ ],
+ "loc": {
+ "start": 0,
+ "end": 65
+ },
+ "type": "ObjectTypeExtension"
+ },
+ {
+ "kind": "InputObjectTypeDefinition",
+ "name": {
+ "kind": "Name",
+ "value": "Credentials",
+ "loc": {
+ "start": 73,
+ "end": 84
+ },
+ "type": "Name"
+ },
+ "directives": [],
+ "fields": [
+ {
+ "kind": "InputValueDefinition",
+ "name": {
+ "kind": "Name",
+ "value": "login",
+ "loc": {
+ "start": 91,
+ "end": 96
+ },
+ "type": "Name"
+ },
+ "type": "InputValueDefinition",
+ "directives": [],
+ "loc": {
+ "start": 91,
+ "end": 105
+ },
+ "fieldType": {
+ "kind": "NonNullType",
+ "type": "NonNullType",
+ "loc": {
+ "start": 98,
+ "end": 105
+ },
+ "fieldType": {
+ "kind": "NamedType",
+ "name": {
+ "kind": "Name",
+ "value": "String",
+ "loc": {
+ "start": 98,
+ "end": 104
+ },
+ "type": "Name"
+ },
+ "loc": {
+ "start": 98,
+ "end": 104
+ },
+ "type": "NamedType"
+ }
+ }
+ },
+ {
+ "kind": "InputValueDefinition",
+ "name": {
+ "kind": "Name",
+ "value": "password",
+ "loc": {
+ "start": 110,
+ "end": 118
+ },
+ "type": "Name"
+ },
+ "type": "InputValueDefinition",
+ "directives": [],
+ "loc": {
+ "start": 110,
+ "end": 127
+ },
+ "fieldType": {
+ "kind": "NonNullType",
+ "type": "NonNullType",
+ "loc": {
+ "start": 120,
+ "end": 127
+ },
+ "fieldType": {
+ "kind": "NamedType",
+ "name": {
+ "kind": "Name",
+ "value": "String",
+ "loc": {
+ "start": 120,
+ "end": 126
+ },
+ "type": "Name"
+ },
+ "loc": {
+ "start": 120,
+ "end": 126
+ },
+ "type": "NamedType"
+ }
+ }
+ }
+ ],
+ "loc": {
+ "start": 67,
+ "end": 129
+ },
+ "type": "InputObjectTypeDefinition"
+ }
+ ],
+ "loc": {
+ "start": 0,
+ "end": 130
+ },
+ "type": "Document",
+ "tokens": [],
+ "comments": [],
+ "range": {}
+ },
+ services: {},
+ scopeManager: { variables: [], scopes: [{ set: new Map(), variables: [], through: [] }], getDeclaredVariables: () => {} },
+ visitorKeys: {
+ Document: ['definitions'],
+ ObjectTypeDefinition: ['interfaces', 'directives', 'fields'],
+ ObjectTypeExtension: ['interfaces', 'directives', 'fields'],
+ InputObjectTypeDefinition: ['directives', 'fields'],
+ InputValueDefinition: ['directives', 'fieldType'],
+ FieldDefinition: ['directives', 'fieldType', 'arguments'],
+ EnumTypeDefinition: ['directives', 'values']
+ }
+});
assert.strictEqual(config.parser, "@typescript-eslint/parser");
assert.deepStrictEqual(config.plugins, ["@typescript-eslint"]);
- assert.deepStrictEqual(config.extends, ["eslint:recommended", "plugin:@typescript-eslint/eslint-recommended"]);
+ assert.deepStrictEqual(config.extends, ["eslint:recommended", "plugin:@typescript-eslint/eslint-recommended", "plugin:@typescript-eslint/recommended"]);
});
it("should enable typescript parser and plugin with vue", () => {
answers.typescript = true;
const config = init.processAnswers(answers);
+ assert.deepStrictEqual(config.extends, ["eslint:recommended", "plugin:vue/essential", "plugin:@typescript-eslint/eslint-recommended", "plugin:@typescript-eslint/recommended"]);
assert.strictEqual(config.parserOptions.parser, "@typescript-eslint/parser");
assert.deepStrictEqual(config.plugins, ["vue", "@typescript-eslint"]);
});
assert.strictEqual(messages.length, 0);
});
+ it("should not throw or return errors when the custom parser returns unknown AST nodes", () => {
+ const code = "foo && bar %% baz";
+
+ const nodes = [];
+
+ linter.defineRule("collect-node-types", () => ({
+ "*"(node) {
+ nodes.push(node.type);
+ }
+ }));
+
+ linter.defineParser("non-js-parser", testParsers.nonJSParser);
+
+ const messages = linter.verify(code, {
+ parser: "non-js-parser",
+ rules: {
+ "collect-node-types": "error"
+ }
+ }, filename, true);
+
+ assert.strictEqual(messages.length, 0);
+ assert.isTrue(nodes.length > 0);
+ });
+
it("should strip leading line: prefix from parser error", () => {
linter.defineParser("line-error", testParsers.lineError);
const messages = linter.verify(";", { parser: "line-error" }, "filename");
"(a) => {\n}",
"a.then((foo) => {});",
"a.then((foo) => { if (true) {}; });",
+ "const f = (/* */a) => a + a;",
+ "const f = (a/** */) => a + a;",
+ "const f = (a//\n) => a + a;",
+ "const f = (//\na) => a + a;",
+ "const f = (/*\n */a//\n) => a + a;",
+ "const f = (/** @type {number} */a/**hello*/) => a + a;",
{ code: "a.then(async (foo) => { if (true) {}; });", parserOptions: { ecmaVersion: 8 } },
// "always" (explicit)
{ code: "async a => ({})", options: ["as-needed", { requireForBlockBody: true }], parserOptions: { ecmaVersion: 8 } },
{ code: "async a => a", options: ["as-needed", { requireForBlockBody: true }], parserOptions: { ecmaVersion: 8 } },
{ code: "(a: T) => a", options: ["as-needed", { requireForBlockBody: true }], parser: parser("identifer-type") },
- { code: "(a): T => a", options: ["as-needed", { requireForBlockBody: true }], parser: parser("return-type") }
+ { code: "(a): T => a", options: ["as-needed", { requireForBlockBody: true }], parser: parser("return-type") },
+ {
+ code: "const f = (/** @type {number} */a/**hello*/) => a + a;",
+ options: ["as-needed"]
+ },
+ {
+ code: "const f = (/* */a) => a + a;",
+ options: ["as-needed"]
+ },
+ {
+ code: "const f = (a/** */) => a + a;",
+ options: ["as-needed"]
+ },
+ {
+ code: "const f = (a//\n) => a + a;",
+ options: ["as-needed"]
+ },
+ {
+ code: "const f = (//\na) => a + a;",
+ options: ["as-needed"]
+ },
+ {
+ code: "const f = (/*\n */a//\n) => a + a;",
+ options: ["as-needed"]
+ },
+ {
+ code: "var foo = (a,/**/) => b;",
+ parserOptions: { ecmaVersion: 2017 },
+ options: ["as-needed"]
+ },
+ {
+ code: "var foo = (a , /**/) => b;",
+ parserOptions: { ecmaVersion: 2017 },
+ options: ["as-needed"]
+ },
+ {
+ code: "var foo = (a\n,\n/**/) => b;",
+ parserOptions: { ecmaVersion: 2017 },
+ options: ["as-needed"]
+ },
+ {
+ code: "var foo = (a,//\n) => b;",
+ parserOptions: { ecmaVersion: 2017 },
+ options: ["as-needed"]
+ },
+ {
+ code: "const i = (a/**/,) => a + a;",
+ parserOptions: { ecmaVersion: 2017 },
+ options: ["as-needed"]
+ },
+ {
+ code: "const i = (a \n /**/,) => a + a;",
+ parserOptions: { ecmaVersion: 2017 },
+ options: ["as-needed"]
+ },
+ {
+ code: "var bar = ({/*comment here*/a}) => a",
+ options: ["as-needed"]
+ },
+ {
+ code: "var bar = (/*comment here*/{a}) => a",
+ options: ["as-needed"]
+ }
];
const type = "ArrowFunctionExpression";
messageId: "unexpectedParensInline",
type
}]
+ },
+ {
+ code: "const f = /** @type {number} */(a)/**hello*/ => a + a;",
+ options: ["as-needed"],
+ output: "const f = /** @type {number} */a/**hello*/ => a + a;",
+ errors: [{
+ line: 1,
+ column: 33,
+ type,
+ messageId: "unexpectedParens",
+ endLine: 1,
+ endColumn: 34
+ }]
+ },
+ {
+ code: "const f = //\n(a) => a + a;",
+ output: "const f = //\na => a + a;",
+ options: ["as-needed"],
+ errors: [{
+ line: 2,
+ column: 2,
+ type,
+ messageId: "unexpectedParens",
+ endLine: 2,
+ endColumn: 3
+ }]
+ },
+ {
+ code: "var foo = /**/ a => b;",
+ output: "var foo = /**/ (a) => b;",
+ errors: [{
+ line: 1,
+ column: 16,
+ type: "ArrowFunctionExpression",
+ messageId: "expectedParens",
+ endLine: 1,
+ endColumn: 17
+ }]
+ },
+ {
+ code: "var bar = a /**/ => b;",
+ output: "var bar = (a) /**/ => b;",
+ errors: [{
+ line: 1,
+ column: 11,
+ type: "ArrowFunctionExpression",
+ messageId: "expectedParens",
+ endLine: 1,
+ endColumn: 12
+ }]
+ },
+ {
+ code: `const foo = a => {};
+
+// comment between 'a' and an unrelated closing paren
+
+bar();`,
+ output: `const foo = (a) => {};
+
+// comment between 'a' and an unrelated closing paren
+
+bar();`,
+ errors: [{
+ line: 1,
+ column: 13,
+ type: "ArrowFunctionExpression",
+ messageId: "expectedParens",
+ endLine: 1,
+ endColumn: 14
+ }]
}
+
];
ruleTester.run("arrow-parens", rule, {
code: "try {foo();} catch (e) {foo();} finally {foo();}",
output: "try { foo(); } catch (e) { foo(); } finally { foo(); }",
errors: [
- { type: "BlockStatement", line: 1, column: 5, messageId: "missing", data: { location: "after", token: "{" } },
- { type: "BlockStatement", line: 1, column: 12, messageId: "missing", data: { location: "before", token: "}" } },
- { type: "BlockStatement", line: 1, column: 24, messageId: "missing", data: { location: "after", token: "{" } },
- { type: "BlockStatement", line: 1, column: 31, messageId: "missing", data: { location: "before", token: "}" } },
- { type: "BlockStatement", line: 1, column: 41, messageId: "missing", data: { location: "after", token: "{" } },
- { type: "BlockStatement", line: 1, column: 48, messageId: "missing", data: { location: "before", token: "}" } }
+ {
+ type: "BlockStatement",
+ messageId: "missing",
+ data: { location: "after", token: "{" },
+ line: 1,
+ column: 5,
+ endLine: 1,
+ endColumn: 6
+ },
+ {
+ type: "BlockStatement",
+ messageId: "missing",
+ data: { location: "before", token: "}" },
+ line: 1,
+ column: 12,
+ endLine: 1,
+ endColumn: 13
+ },
+ {
+ type: "BlockStatement",
+ messageId: "missing",
+ data: { location: "after", token: "{" },
+ line: 1,
+ column: 24,
+ endLine: 1,
+ endColumn: 25
+ },
+ {
+ type: "BlockStatement",
+ messageId: "missing",
+ data: { location: "before", token: "}" },
+ line: 1,
+ column: 31,
+ endLine: 1,
+ endColumn: 32
+ },
+ {
+ type: "BlockStatement",
+ messageId: "missing",
+ data: { location: "after", token: "{" },
+ line: 1,
+ column: 41,
+ endLine: 1,
+ endColumn: 42
+ },
+ {
+ type: "BlockStatement",
+ messageId: "missing",
+ data: { location: "before", token: "}" },
+ line: 1,
+ column: 48,
+ endLine: 1,
+ endColumn: 49
+ }
]
},
{
output: "if (a) { //comment\n foo(); }",
parserOptions: { ecmaVersion: 6 },
errors: [
- { type: "BlockStatement", line: 1, column: 8, messageId: "missing", data: { location: "after", token: "{" } }
+ {
+ type: "BlockStatement",
+ messageId: "missing",
+ data: {
+ location: "after",
+ token: "{"
+ },
+ line: 1,
+ column: 8,
+ endLine: 1,
+ endColumn: 9
+ }
]
},
output: "{foo();}",
options: ["never"],
errors: [
- { type: "BlockStatement", line: 1, column: 1, messageId: "extra", data: { location: "after", token: "{" } },
- { type: "BlockStatement", line: 1, column: 10, messageId: "extra", data: { location: "before", token: "}" } }
+ {
+ type: "BlockStatement",
+ messageId: "extra",
+ data: { location: "after", token: "{" },
+ line: 1,
+ column: 2,
+ endLine: 1,
+ endColumn: 3
+ },
+ {
+ type: "BlockStatement",
+ messageId: "extra",
+ data: { location: "before", token: "}" },
+ line: 1,
+ column: 9,
+ endLine: 1,
+ endColumn: 10
+ }
]
},
{
output: "{foo();}",
options: ["never"],
errors: [
- { type: "BlockStatement", line: 1, column: 1, messageId: "extra", data: { location: "after", token: "{" } }
+ {
+ type: "BlockStatement",
+ messageId: "extra",
+ data: {
+ location: "after",
+ token: "{"
+ },
+ line: 1,
+ column: 2,
+ endLine: 1,
+ endColumn: 3
+ }
]
},
{
output: "{foo();}",
options: ["never"],
errors: [
- { type: "BlockStatement", line: 1, column: 9, messageId: "extra", data: { location: "before", token: "}" } }
+ {
+ type: "BlockStatement",
+ messageId: "extra",
+ data: {
+ location: "before",
+ token: "}"
+ },
+ line: 1,
+ column: 8,
+ endLine: 1,
+ endColumn: 9
+ }
]
},
{
output: "{\nfoo();}",
options: ["never"],
errors: [
- { type: "BlockStatement", line: 2, column: 8, messageId: "extra", data: { location: "before", token: "}" } }
+ {
+ type: "BlockStatement",
+ messageId: "extra",
+ data: {
+ location: "before",
+ token: "}"
+ },
+ line: 2,
+ column: 7,
+ endLine: 2,
+ endColumn: 8
+ }
]
},
{
output: "{foo();\n}",
options: ["never"],
errors: [
- { type: "BlockStatement", line: 1, column: 1, messageId: "extra", data: { location: "after", token: "{" } }
+ {
+ type: "BlockStatement",
+ messageId: "extra",
+ data: {
+ location: "after",
+ token: "{"
+ },
+ line: 1,
+ column: 2,
+ endLine: 1,
+ endColumn: 3
+ }
]
},
{
output: "if (a) {foo();}",
options: ["never"],
errors: [
- { type: "BlockStatement", line: 1, column: 8, messageId: "extra", data: { location: "after", token: "{" } },
- { type: "BlockStatement", line: 1, column: 17, messageId: "extra", data: { location: "before", token: "}" } }
+ {
+ type: "BlockStatement",
+ messageId: "extra",
+ data: { location: "after", token: "{" },
+ line: 1,
+ column: 9,
+ endLine: 1,
+ endColumn: 10
+ },
+ {
+ type: "BlockStatement",
+ messageId: "extra",
+ data: { location: "before", token: "}" },
+ line: 1,
+ column: 16,
+ endLine: 1,
+ endColumn: 17
+ }
]
},
{
output: "if (a) {} else {foo();}",
options: ["never"],
errors: [
- { type: "BlockStatement", line: 1, column: 16, messageId: "extra", data: { location: "after", token: "{" } },
- { type: "BlockStatement", line: 1, column: 25, messageId: "extra", data: { location: "before", token: "}" } }
+ {
+ type: "BlockStatement",
+ messageId: "extra",
+ data: { location: "after", token: "{" },
+ line: 1,
+ column: 17,
+ endLine: 1,
+ endColumn: 18
+ },
+ {
+ type: "BlockStatement",
+ messageId: "extra",
+ data: { location: "before", token: "}" },
+ line: 1,
+ column: 24,
+ endLine: 1,
+ endColumn: 25
+ }
]
},
{
output: "switch (a) {case 0: foo();}",
options: ["never"],
errors: [
- { type: "SwitchStatement", line: 1, column: 12, messageId: "extra", data: { location: "after", token: "{" } },
- { type: "SwitchStatement", line: 1, column: 29, messageId: "extra", data: { location: "before", token: "}" } }
+ {
+ type: "SwitchStatement",
+ messageId: "extra",
+ data: { location: "after", token: "{" },
+ line: 1,
+ column: 13,
+ endLine: 1,
+ endColumn: 14
+ },
+ {
+ type: "SwitchStatement",
+ messageId: "extra",
+ data: { location: "before", token: "}" },
+ line: 1,
+ column: 28,
+ endLine: 1,
+ endColumn: 29
+ }
]
},
{
output: "while (a) {foo();}",
options: ["never"],
errors: [
- { type: "BlockStatement", line: 1, column: 11, messageId: "extra", data: { location: "after", token: "{" } },
- { type: "BlockStatement", line: 1, column: 20, messageId: "extra", data: { location: "before", token: "}" } }
+ {
+ type: "BlockStatement",
+ messageId: "extra",
+ data: { location: "after", token: "{" },
+ line: 1,
+ column: 12,
+ endLine: 1,
+ endColumn: 13
+ },
+ {
+ type: "BlockStatement",
+ messageId: "extra",
+ data: { location: "before", token: "}" },
+ line: 1,
+ column: 19,
+ endLine: 1,
+ endColumn: 20
+ }
]
},
{
output: "do {foo();} while (a);",
options: ["never"],
errors: [
- { type: "BlockStatement", line: 1, column: 4, messageId: "extra", data: { location: "after", token: "{" } },
- { type: "BlockStatement", line: 1, column: 13, messageId: "extra", data: { location: "before", token: "}" } }
+ {
+ type: "BlockStatement",
+ messageId: "extra",
+ data: { location: "after", token: "{" },
+ line: 1,
+ column: 5,
+ endLine: 1,
+ endColumn: 6
+ },
+ {
+ type: "BlockStatement",
+ messageId: "extra",
+ data: { location: "before", token: "}" },
+ line: 1,
+ column: 12,
+ endLine: 1,
+ endColumn: 13
+ }
]
},
{
output: "for (;;) {foo();}",
options: ["never"],
errors: [
- { type: "BlockStatement", line: 1, column: 10, messageId: "extra", data: { location: "after", token: "{" } },
- { type: "BlockStatement", line: 1, column: 19, messageId: "extra", data: { location: "before", token: "}" } }
+ {
+ type: "BlockStatement",
+ messageId: "extra",
+ data: { location: "after", token: "{" },
+ line: 1,
+ column: 11,
+ endLine: 1,
+ endColumn: 12
+ },
+ {
+ type: "BlockStatement",
+ messageId: "extra",
+ data: { location: "before", token: "}" },
+ line: 1,
+ column: 18,
+ endLine: 1,
+ endColumn: 19
+ }
]
},
{
output: "for (var a in b) {foo();}",
options: ["never"],
errors: [
- { type: "BlockStatement", line: 1, column: 18, messageId: "extra", data: { location: "after", token: "{" } },
- { type: "BlockStatement", line: 1, column: 27, messageId: "extra", data: { location: "before", token: "}" } }
+ {
+ type: "BlockStatement",
+ messageId: "extra",
+ data: { location: "after", token: "{" },
+ line: 1,
+ column: 19,
+ endLine: 1,
+ endColumn: 20
+ },
+ {
+ type: "BlockStatement",
+ messageId: "extra",
+ data: { location: "before", token: "}" },
+ line: 1,
+ column: 26,
+ endLine: 1,
+ endColumn: 27
+ }
]
},
{
options: ["never"],
parserOptions: { ecmaVersion: 6 },
errors: [
- { type: "BlockStatement", line: 1, column: 18, messageId: "extra", data: { location: "after", token: "{" } },
- { type: "BlockStatement", line: 1, column: 27, messageId: "extra", data: { location: "before", token: "}" } }
+ {
+ type: "BlockStatement",
+ messageId: "extra",
+ data: { location: "after", token: "{" },
+ line: 1,
+ column: 19,
+ endLine: 1,
+ endColumn: 20
+ },
+ {
+ type: "BlockStatement",
+ messageId: "extra",
+ data: { location: "before", token: "}" },
+ line: 1,
+ column: 26,
+ endLine: 1,
+ endColumn: 27
+ }
]
},
{
output: "try {foo();} catch (e) {foo();} finally {foo();}",
options: ["never"],
errors: [
- { type: "BlockStatement", line: 1, column: 5, messageId: "extra", data: { location: "after", token: "{" } },
- { type: "BlockStatement", line: 1, column: 14, messageId: "extra", data: { location: "before", token: "}" } },
- { type: "BlockStatement", line: 1, column: 26, messageId: "extra", data: { location: "after", token: "{" } },
- { type: "BlockStatement", line: 1, column: 35, messageId: "extra", data: { location: "before", token: "}" } },
- { type: "BlockStatement", line: 1, column: 45, messageId: "extra", data: { location: "after", token: "{" } },
- { type: "BlockStatement", line: 1, column: 54, messageId: "extra", data: { location: "before", token: "}" } }
+ {
+ type: "BlockStatement",
+ messageId: "extra",
+ data: { location: "after", token: "{" },
+ line: 1,
+ column: 6,
+ endLine: 1,
+ endColumn: 7
+ },
+ {
+ type: "BlockStatement",
+ messageId: "extra",
+ data: { location: "before", token: "}" },
+ line: 1,
+ column: 13,
+ endLine: 1,
+ endColumn: 14
+ },
+ {
+ type: "BlockStatement",
+ messageId: "extra",
+ data: { location: "after", token: "{" },
+ line: 1,
+ column: 27,
+ endLine: 1,
+ endColumn: 28
+ },
+ {
+ type: "BlockStatement",
+ line: 1,
+ column: 34,
+ messageId: "extra",
+ data: { location: "before", token: "}" },
+ endLine: 1,
+ endColumn: 35
+ },
+ {
+ type: "BlockStatement",
+ messageId: "extra",
+ data: { location: "after", token: "{" },
+ line: 1,
+ column: 46,
+ endLine: 1,
+ endColumn: 47
+ },
+ {
+ type: "BlockStatement",
+ messageId: "extra",
+ data: { location: "before", token: "}" },
+ line: 1,
+ column: 53,
+ endLine: 1,
+ endColumn: 54
+ }
]
},
{
output: "function foo() {bar();}",
options: ["never"],
errors: [
- { type: "BlockStatement", line: 1, column: 16, messageId: "extra", data: { location: "after", token: "{" } },
- { type: "BlockStatement", line: 1, column: 25, messageId: "extra", data: { location: "before", token: "}" } }
+ {
+ type: "BlockStatement",
+ messageId: "extra",
+ data: { location: "after", token: "{" },
+ line: 1,
+ column: 17,
+ endLine: 1,
+ endColumn: 18
+ },
+ {
+ type: "BlockStatement",
+ messageId: "extra",
+ data: { location: "before", token: "}" },
+ line: 1,
+ column: 24,
+ endLine: 1,
+ endColumn: 25
+ }
]
},
{
output: "(function() {bar();});",
options: ["never"],
errors: [
- { type: "BlockStatement", line: 1, column: 13, messageId: "extra", data: { location: "after", token: "{" } },
- { type: "BlockStatement", line: 1, column: 22, messageId: "extra", data: { location: "before", token: "}" } }
+ {
+ type: "BlockStatement",
+ messageId: "extra",
+ data: { location: "after", token: "{" },
+ line: 1,
+ column: 14,
+ endLine: 1,
+ endColumn: 15
+ },
+ {
+ type: "BlockStatement",
+ messageId: "extra",
+ data: { location: "before", token: "}" },
+ line: 1,
+ column: 21,
+ endLine: 1,
+ endColumn: 22
+ }
]
},
{
options: ["never"],
parserOptions: { ecmaVersion: 6 },
errors: [
- { type: "BlockStatement", line: 1, column: 8, messageId: "extra", data: { location: "after", token: "{" } },
- { type: "BlockStatement", line: 1, column: 17, messageId: "extra", data: { location: "before", token: "}" } }
+ {
+ type: "BlockStatement",
+ messageId: "extra",
+ data: { location: "after", token: "{" },
+ line: 1,
+ column: 9,
+ endLine: 1,
+ endColumn: 10
+ },
+ {
+ type: "BlockStatement",
+ messageId: "extra",
+ data: { location: "before", token: "}" },
+ line: 1,
+ column: 16,
+ endLine: 1,
+ endColumn: 17
+ }
]
},
{
output: "if (a) {/* comment */ foo(); /* comment */}",
options: ["never"],
errors: [
- { type: "BlockStatement", line: 1, column: 8, messageId: "extra", data: { location: "after", token: "{" } },
- { type: "BlockStatement", line: 1, column: 45, messageId: "extra", data: { location: "before", token: "}" } }
+ {
+ type: "BlockStatement",
+ messageId: "extra",
+ data: { location: "after", token: "{" },
+ line: 1,
+ column: 9,
+ endLine: 1,
+ endColumn: 10
+ },
+ {
+ type: "BlockStatement",
+ messageId: "extra",
+ data: { location: "before", token: "}" },
+ line: 1,
+ column: 44,
+ endLine: 1,
+ endColumn: 45
+ }
+ ]
+ },
+ {
+ code: "(() => { bar();});",
+ output: "(() => {bar();});",
+ options: ["never"],
+ parserOptions: { ecmaVersion: 6 },
+ errors: [
+ {
+ type: "BlockStatement",
+ messageId: "extra",
+ data: { location: "after", token: "{" },
+ line: 1,
+ column: 9,
+ endLine: 1,
+ endColumn: 12
+ }
+ ]
+ },
+ {
+ code: "(() => {bar(); });",
+ output: "(() => {bar();});",
+ options: ["never"],
+ parserOptions: { ecmaVersion: 6 },
+ errors: [
+ {
+ type: "BlockStatement",
+ messageId: "extra",
+ data: { location: "before", token: "}" },
+ line: 1,
+ column: 15,
+ endLine: 1,
+ endColumn: 18
+ }
+ ]
+ },
+ {
+ code: "(() => { bar(); });",
+ output: "(() => {bar();});",
+ options: ["never"],
+ parserOptions: { ecmaVersion: 6 },
+ errors: [
+ {
+ type: "BlockStatement",
+ messageId: "extra",
+ data: { location: "after", token: "{" },
+ line: 1,
+ column: 9,
+ endLine: 1,
+ endColumn: 12
+ },
+ {
+ type: "BlockStatement",
+ messageId: "extra",
+ data: { location: "before", token: "}" },
+ line: 1,
+ column: 18,
+ endLine: 1,
+ endColumn: 21
+ }
]
}
]
}
]
},
+ {
+ code: "var foo = {\nbar: 'baz'\r\n}",
+ output: "var foo = {\nbar: 'baz',\r\n}",
+ options: ["always"],
+ errors: [
+ {
+ messageId: "missing",
+ type: "Property",
+ line: 2,
+ column: 11,
+ endLine: 3,
+ endColumn: 1
+ }
+ ]
+ },
{
code: "foo({ bar: 'baz', qux: 'quux' });",
output: "foo({ bar: 'baz', qux: 'quux', });",
errors: [{
line: 1,
column: 13,
+ endLine: 2,
+ endColumn: 1,
messageId: "expectedLF"
}]
},
errors: [{
line: 1,
column: 13,
+ endLine: 2,
+ endColumn: 1,
messageId: "expectedLF"
}]
},
errors: [{
line: 1,
column: 13,
+ endLine: 2,
+ endColumn: 1,
messageId: "expectedCRLF"
}]
},
errors: [{
line: 4,
column: 24,
+ endLine: 5,
+ endColumn: 1,
messageId: "expectedLF"
},
{
line: 6,
column: 3,
+ endLine: 7,
+ endColumn: 1,
messageId: "expectedLF"
}]
},
errors: [{
line: 3,
column: 1,
+ endLine: 4,
+ endColumn: 1,
messageId: "expectedCRLF"
},
{
line: 5,
column: 1,
+ endLine: 6,
+ endColumn: 1,
messageId: "expectedCRLF"
},
{
line: 6,
column: 17,
+ endLine: 7,
+ endColumn: 1,
+ messageId: "expectedCRLF"
+ }]
+ },
+ {
+ code: "\r\n",
+ output: "\n",
+ options: ["unix"],
+ errors: [{
+ line: 1,
+ column: 1,
+ endLine: 2,
+ endColumn: 1,
+ messageId: "expectedLF"
+ }]
+ },
+ {
+ code: "\n",
+ output: "\r\n",
+ options: ["windows"],
+ errors: [{
+ line: 1,
+ column: 1,
+ endLine: 2,
+ endColumn: 1,
messageId: "expectedCRLF"
}]
}
return bar;
}());`,
options: [{ max: 2, skipComments: true, skipBlankLines: false, IIFEs: false }]
+ },
+
+ // Arrow IIFEs should be recognised if IIFEs: true
+ {
+ code: `(() => {
+ let x = 0;
+ let y = 0;
+ let z = x + y;
+ let foo = {};
+ return bar;
+})();`,
+ options: [{ max: 7, skipComments: true, skipBlankLines: false, IIFEs: true }]
+ },
+
+ // Arrow IIFEs should not be recognised if IIFEs: false
+ {
+ code: `(() => {
+ let x = 0;
+ let y = 0;
+ let z = x + y;
+ let foo = {};
+ return bar;
+})();`,
+ options: [{ max: 2, skipComments: true, skipBlankLines: false, IIFEs: false }]
}
],
errors: [
{ messageId: "exceed", data: { name: "Function", lineCount: 7, maxLines: 2 } }
]
+ },
+
+ // Test the IIFEs option includes arrow IIFEs
+ {
+ code: `(() => {
+ let x = 0;
+ let y = 0;
+ let z = x + y;
+ let foo = {};
+ return bar;
+})();`,
+ options: [{ max: 2, skipComments: true, skipBlankLines: false, IIFEs: true }],
+ errors: [
+ { messageId: "exceed", data: { name: "Arrow function", lineCount: 7, maxLines: 2 } }
+ ]
}
]
});
--- /dev/null
+/**
+ *@fileoverview Tests for no-loss-of-precision rule.
+ *@author Jacob Moore
+ */
+
+"use strict";
+
+//------------------------------------------------------------------------------
+// Requirements
+//------------------------------------------------------------------------------
+
+const rule = require("../../../lib/rules/no-loss-of-precision"),
+ { RuleTester } = require("../../../lib/rule-tester");
+
+//------------------------------------------------------------------------------
+// Helpers
+//------------------------------------------------------------------------------
+
+const ruleTester = new RuleTester();
+
+ruleTester.run("no-loss-of-precision", rule, {
+ valid: [
+ "var x = 12345",
+ "var x = 123.456",
+ "var x = -123.456",
+ "var x = -123456",
+ "var x = 123e34",
+ "var x = 123.0e34",
+ "var x = 123e-34",
+ "var x = -123e34",
+ "var x = -123e-34",
+ "var x = 12.3e34",
+ "var x = 12.3e-34",
+ "var x = -12.3e34",
+ "var x = -12.3e-34",
+ "var x = 12300000000000000000000000",
+ "var x = -12300000000000000000000000",
+ "var x = 0.00000000000000000000000123",
+ "var x = -0.00000000000000000000000123",
+ "var x = 9007199254740991",
+ "var x = 0",
+ "var x = 0.0",
+ "var x = 0.000000000000000000000000000000000000000000000000000000000000000000000000000000",
+ "var x = -0",
+ "var x = 123.0000000000000000000000",
+ "var x = 019.5",
+ "var x = 0195",
+ "var x = 0e5",
+
+
+ { code: "var x = 0b11111111111111111111111111111111111111111111111111111", parserOptions: { ecmaVersion: 6 } },
+ { code: "var x = 0B11111111111111111111111111111111111111111111111111111", parserOptions: { ecmaVersion: 6 } },
+
+ { code: "var x = 0o377777777777777777", parserOptions: { ecmaVersion: 6 } },
+ { code: "var x = 0O377777777777777777", parserOptions: { ecmaVersion: 6 } },
+ "var x = 0377777777777777777",
+
+ "var x = 0x1FFFFFFFFFFFFF",
+ "var x = 0X1FFFFFFFFFFFFF",
+ "var x = true",
+ "var x = 'abc'",
+ "var x = ''",
+ "var x = null",
+ "var x = undefined",
+ "var x = {}",
+ "var x = ['a', 'b']",
+ "var x = new Date()",
+ "var x = '9007199254740993'"
+
+ ],
+ invalid: [
+ {
+ code: "var x = 9007199254740993",
+ errors: [{ messageId: "noLossOfPrecision" }]
+ },
+ {
+ code: "var x = 9007199254740.993e3",
+ errors: [{ messageId: "noLossOfPrecision" }]
+ },
+ {
+ code: "var x = 9.007199254740993e15",
+ errors: [{ messageId: "noLossOfPrecision" }]
+ },
+ {
+ code: "var x = -9007199254740993",
+ errors: [{ messageId: "noLossOfPrecision" }]
+ },
+ {
+ code: "var x = 900719.9254740994",
+ errors: [{ messageId: "noLossOfPrecision" }]
+ },
+ {
+ code: "var x = -900719.9254740994",
+ errors: [{ messageId: "noLossOfPrecision" }]
+ },
+
+ {
+ code: "var x = 5123000000000000000000000000001",
+ errors: [{ messageId: "noLossOfPrecision" }]
+ },
+ {
+ code: "var x = -5123000000000000000000000000001",
+ errors: [{ messageId: "noLossOfPrecision" }]
+ },
+ {
+ code: "var x = 1230000000000000000000000.0",
+ errors: [{ messageId: "noLossOfPrecision" }]
+ },
+ {
+ code: "var x = 1.0000000000000000000000123",
+ errors: [{ messageId: "noLossOfPrecision" }]
+ },
+ {
+ code: "var x = 17498005798264095394980017816940970922825355447145699491406164851279623993595007385788105416184430592",
+ errors: [{ messageId: "noLossOfPrecision" }]
+ },
+ {
+ code: "var x = 2e999",
+ errors: [{ messageId: "noLossOfPrecision" }]
+ },
+ {
+ code: "var x = .1230000000000000000000000",
+ errors: [{ messageId: "noLossOfPrecision" }]
+ },
+ {
+ code: "var x = 0b100000000000000000000000000000000000000000000000000001",
+ parserOptions: { ecmaVersion: 6 },
+ errors: [{ messageId: "noLossOfPrecision" }]
+ },
+ {
+ code: "var x = 0B100000000000000000000000000000000000000000000000000001",
+ parserOptions: { ecmaVersion: 6 },
+ errors: [{ messageId: "noLossOfPrecision" }]
+ },
+ {
+ code: "var x = 0o400000000000000001",
+ parserOptions: { ecmaVersion: 6 },
+ errors: [{ messageId: "noLossOfPrecision" }]
+ },
+ {
+ code: "var x = 0O400000000000000001",
+ parserOptions: { ecmaVersion: 6 },
+ errors: [{ messageId: "noLossOfPrecision" }]
+ },
+ {
+ code: "var x = 0400000000000000001",
+ errors: [{ messageId: "noLossOfPrecision" }]
+ },
+ {
+ code: "var x = 0x20000000000001",
+ errors: [{ messageId: "noLossOfPrecision" }]
+ },
+ {
+ code: "var x = 0X20000000000001",
+ errors: [{ messageId: "noLossOfPrecision" }]
+ }
+
+ ]
+});
ruleTester.run("no-new-func", rule, {
valid: [
"var a = new _function(\"b\", \"c\", \"return b+c\");",
- "var a = _function(\"b\", \"c\", \"return b+c\");"
+ "var a = _function(\"b\", \"c\", \"return b+c\");",
+ {
+ code: "class Function {}; new Function()",
+ parserOptions: {
+ ecmaVersion: 2015
+ }
+ },
+ {
+ code: "const fn = () => { class Function {}; new Function() }",
+ parserOptions: {
+ ecmaVersion: 2015
+ }
+ },
+ "function Function() {}; Function()",
+ "var fn = function () { function Function() {}; Function() }",
+ "var x = function Function() { Function(); }",
+ "call(Function)",
+ "new Class(Function)"
],
invalid: [
{
messageId: "noFunctionConstructor",
type: "CallExpression"
}]
+ },
+ {
+ code: "const fn = () => { class Function {} }; new Function('', '')",
+ parserOptions: {
+ ecmaVersion: 2015
+ },
+ errors: [{
+ messageId: "noFunctionConstructor",
+ type: "NewExpression"
+ }]
+ },
+ {
+ code: "var fn = function () { function Function() {} }; Function('', '')",
+ errors: [{
+ messageId: "noFunctionConstructor",
+ type: "CallExpression"
+ }]
}
]
});
valid: [
"var foo = Symbol('foo');",
"function bar(Symbol) { var baz = new Symbol('baz');}",
- "function Symbol() {} new Symbol();"
+ "function Symbol() {} new Symbol();",
+ "new foo(Symbol);",
+ "new foo(bar, Symbol);"
],
invalid: [
{
],
invalid: [
+ { code: "var foo, bar;", output: "var foo, \nbar;", options: ["always"], errors: [{ line: 1, column: 10, endLine: 1, endColumn: 13 }] },
{ code: "var a, b;", output: "var a, \nb;", options: ["always"], errors: [errorAt(1, 8)] },
{ code: "let a, b;", output: "let a, \nb;", options: ["always"], parserOptions: { ecmaVersion: 6 }, errors: [errorAt(1, 8)] },
{ code: "var a, b = 0;", output: "var a, \nb = 0;", options: ["always"], errors: [errorAt(1, 8)] },
{ code: "let a, b = 0;", output: "let a, \nb = 0;", options: ["always"], parserOptions: { ecmaVersion: 6 }, errors: [errorAt(1, 8)] },
{ code: "const a = 0, b = 0;", output: "const a = 0, \nb = 0;", options: ["always"], parserOptions: { ecmaVersion: 6 }, errors: [errorAt(1, 14)] },
+ { code: "var foo, bar, baz = 0;", output: "var foo, bar, \nbaz = 0;", options: ["initializations"], errors: [{ line: 1, column: 15, endLine: 1, endColumn: 22 }] },
{ code: "var a, b, c = 0;", output: "var a, b, \nc = 0;", options: ["initializations"], errors: [errorAt(1, 11)] },
{ code: "var a, b,\nc = 0, d;", output: "var a, b,\nc = 0, \nd;", options: ["initializations"], errors: [errorAt(2, 8)] },
{ code: "var a, b,\nc = 0, d = 0;", output: "var a, b,\nc = 0, \nd = 0;", options: ["initializations"], errors: [errorAt(2, 8)] },
{ code: "{\n\na();\n\n/* comment */ }", options: ["always"] },
{ code: "{\n\na();\n\n/* comment */ }", options: [{ blocks: "always" }] },
+
{ code: "switch (a) {}", options: [{ switches: "always" }] },
{ code: "switch (a) {\n\ncase 0: foo();\ncase 1: bar();\n\n}", options: ["always"] },
{ code: "switch (a) {\n\ncase 0: foo();\ncase 1: bar();\n\n}", options: [{ switches: "always" }] },
{
messageId: "alwaysPadBlock",
line: 1,
- column: 1
+ column: 1,
+ endLine: 2,
+ endColumn: 1
}
]
},
{
messageId: "alwaysPadBlock",
line: 1,
- column: 3
+ column: 3,
+ endLine: 2,
+ endColumn: 1
}
]
},
errors: [
{
messageId: "alwaysPadBlock",
- line: 5,
- column: 1
+ line: 4,
+ column: 10,
+ endLine: 5,
+ endColumn: 1
}
]
},
errors: [
{
messageId: "alwaysPadBlock",
- line: 5,
- column: 1
+ line: 4,
+ column: 10,
+ endLine: 5,
+ endColumn: 1
}
]
},
errors: [
{
messageId: "alwaysPadBlock",
- line: 1
+ line: 1,
+ column: 1,
+ endLine: 2,
+ endColumn: 1
}
]
},
errors: [
{
messageId: "alwaysPadBlock",
- line: 4
+ line: 3,
+ column: 5,
+ endLine: 4,
+ endColumn: 1
}
]
},
errors: [
{
messageId: "alwaysPadBlock",
- line: 1
+ line: 1,
+ column: 1,
+ endLine: 2,
+ endColumn: 1
},
{
messageId: "alwaysPadBlock",
- line: 3
+ line: 2,
+ column: 5,
+ endLine: 3,
+ endColumn: 1
}
]
},
errors: [
{
messageId: "alwaysPadBlock",
- line: 1
+ line: 1,
+ column: 1,
+ endLine: 2,
+ endColumn: 1
},
{
messageId: "alwaysPadBlock",
- line: 3
+ line: 2,
+ column: 5,
+ endLine: 3,
+ endColumn: 1
}
]
},
errors: [
{
messageId: "alwaysPadBlock",
- line: 1
+ line: 1,
+ column: 1,
+ endLine: 2,
+ endColumn: 1
},
{
messageId: "alwaysPadBlock",
- line: 2
+ line: 2,
+ column: 5,
+ endLine: 2,
+ endColumn: 5
}
]
},
errors: [
{
messageId: "alwaysPadBlock",
- line: 1
+ line: 1,
+ column: 1,
+ endLine: 1,
+ endColumn: 2
},
{
messageId: "alwaysPadBlock",
- line: 2
+ line: 1,
+ column: 6,
+ endLine: 2,
+ endColumn: 1
}
]
},
errors: [
{
messageId: "alwaysPadBlock",
- line: 1
+ line: 1,
+ column: 1,
+ endLine: 1,
+ endColumn: 2
},
{
messageId: "alwaysPadBlock",
- line: 2
+ line: 1,
+ column: 6,
+ endLine: 2,
+ endColumn: 1
}
]
},
{
messageId: "alwaysPadBlock",
line: 1,
- column: 12
+ column: 12,
+ endLine: 2,
+ endColumn: 1
},
{
messageId: "alwaysPadBlock",
- line: 4,
- column: 1
+ line: 3,
+ column: 15,
+ endLine: 4,
+ endColumn: 1
}
]
},
{
messageId: "alwaysPadBlock",
line: 1,
- column: 12
+ column: 12,
+ endLine: 2,
+ endColumn: 1
},
{
messageId: "alwaysPadBlock",
- line: 4,
- column: 1
+ line: 3,
+ column: 15,
+ endLine: 4,
+ endColumn: 1
}
]
},
{
messageId: "alwaysPadBlock",
line: 1,
- column: 12
+ column: 12,
+ endLine: 2,
+ endColumn: 1
},
{
messageId: "alwaysPadBlock",
- line: 4,
- column: 1
+ line: 3,
+ column: 24,
+ endLine: 4,
+ endColumn: 1
}
]
},
{
messageId: "alwaysPadBlock",
line: 1,
- column: 9
+ column: 9,
+ endLine: 2,
+ endColumn: 1
},
{
messageId: "alwaysPadBlock",
- line: 3,
- column: 1
+ line: 2,
+ column: 16,
+ endLine: 3,
+ endColumn: 1
}
]
},
{
messageId: "alwaysPadBlock",
line: 1,
- column: 9
+ column: 9,
+ endLine: 2,
+ endColumn: 1
},
{
messageId: "alwaysPadBlock",
- line: 3,
- column: 1
+ line: 2,
+ column: 16,
+ endLine: 3,
+ endColumn: 1
}
]
},
errors: [
{
messageId: "alwaysPadBlock",
- line: 1
+ line: 1,
+ column: 1,
+ endLine: 1,
+ endColumn: 2
},
{
messageId: "alwaysPadBlock",
- line: 1
+ line: 1,
+ column: 6,
+ endLine: 1,
+ endColumn: 6
}
]
},
errors: [
{
messageId: "neverPadBlock",
- line: 5
+ line: 3,
+ column: 10,
+ endLine: 5,
+ endColumn: 1
}
]
},
errors: [
{
messageId: "neverPadBlock",
- line: 1
+ line: 1,
+ column: 1,
+ endLine: 3,
+ endColumn: 1
},
{
messageId: "neverPadBlock",
- line: 5
+ line: 3,
+ column: 5,
+ endLine: 5,
+ endColumn: 1
}
]
},
errors: [
{
messageId: "neverPadBlock",
- line: 1
+ line: 1,
+ column: 1,
+ endLine: 3,
+ endColumn: 1
},
{
messageId: "neverPadBlock",
- line: 5
+ line: 3,
+ column: 5,
+ endLine: 5,
+ endColumn: 1
}
]
},
errors: [
{
messageId: "neverPadBlock",
- line: 1
+ line: 1,
+ column: 1,
+ endLine: 4,
+ endColumn: 3
},
{
messageId: "neverPadBlock",
- line: 7
+ line: 4,
+ column: 7,
+ endLine: 7,
+ endColumn: 1
}
]
},
errors: [
{
messageId: "neverPadBlock",
- line: 1
+ line: 1,
+ column: 1,
+ endLine: 3,
+ endColumn: 1
}
]
},
errors: [
{
messageId: "neverPadBlock",
- line: 1
+ line: 1,
+ column: 1,
+ endLine: 3,
+ endColumn: 2
}
]
},
errors: [
{
messageId: "neverPadBlock",
- line: 4
+ line: 2,
+ column: 5,
+ endLine: 4,
+ endColumn: 1
}
]
},
errors: [
{
messageId: "neverPadBlock",
- line: 4
+ line: 2,
+ column: 9,
+ endLine: 4,
+ endColumn: 3
}
]
},
{
messageId: "alwaysPadBlock",
line: 1,
- column: 1
+ column: 1,
+ endLine: 2,
+ endColumn: 1
}
]
},
{
messageId: "neverPadBlock",
line: 1,
- column: 1
+ column: 1,
+ endLine: 3,
+ endColumn: 1
}
]
},
{
messageId: "neverPadBlock",
line: 1,
- column: 1
+ column: 1,
+ endLine: 3,
+ endColumn: 1
}
]
},
{
messageId: "neverPadBlock",
line: 1,
- column: 12
+ column: 12,
+ endLine: 3,
+ endColumn: 1
},
{
messageId: "neverPadBlock",
- line: 5,
- column: 1
+ line: 3,
+ column: 15,
+ endLine: 5,
+ endColumn: 1
}
]
},
{
messageId: "neverPadBlock",
line: 1,
- column: 12
+ column: 12,
+ endLine: 3,
+ endColumn: 1
}
]
},
errors: [
{
messageId: "neverPadBlock",
- line: 4,
- column: 3
+ line: 2,
+ column: 15,
+ endLine: 4,
+ endColumn: 3
}
]
},
errors: [
{
messageId: "neverPadBlock",
- line: 1
+ line: 1,
+ column: 9,
+ endLine: 3,
+ endColumn: 1
},
{
messageId: "neverPadBlock",
- line: 3
+ line: 3,
+ column: 14,
+ endLine: 5,
+ endColumn: 1
},
{
messageId: "neverPadBlock",
- line: 7
+ line: 5,
+ column: 7,
+ endLine: 7,
+ endColumn: 1
},
{
messageId: "neverPadBlock",
- line: 9
+ line: 7,
+ column: 2,
+ endLine: 9,
+ endColumn: 1
}
]
},
errors: [
{
messageId: "neverPadBlock",
- line: 1
+ line: 1,
+ column: 9,
+ endLine: 3,
+ endColumn: 1
},
{
messageId: "neverPadBlock",
- line: 9
+ line: 7,
+ column: 2,
+ endLine: 9,
+ endColumn: 1
}
]
},
errors: [
{
messageId: "neverPadBlock",
- line: 1
+ line: 1,
+ column: 9,
+ endLine: 3,
+ endColumn: 1
},
{
messageId: "neverPadBlock",
- line: 3
+ line: 3,
+ column: 14,
+ endLine: 5,
+ endColumn: 1
},
{
messageId: "neverPadBlock",
- line: 7
+ line: 5,
+ column: 7,
+ endLine: 7,
+ endColumn: 1
},
{
messageId: "neverPadBlock",
- line: 9
+ line: 7,
+ column: 2,
+ endLine: 9,
+ endColumn: 1
}
]
},
"({ async foo() { await doSomething() } })",
"class A { async foo() { await doSomething() } }",
"(class { async foo() { await doSomething() } })",
- "async function foo() { await async () => { await doSomething() } }",
+ "async function foo() { await (async () => { await doSomething() }) }",
// empty functions are ok.
"async function foo() {}",
}]
},
{
- code: "async function foo() { await async () => { doSomething() } }",
+ code: "async function foo() { await (async () => { doSomething() }) }",
errors: [{
messageId: "missingAwait",
data: { name: "Async arrow function" }
errors: [{
line: 1,
column: 7,
+ endLine: 1,
+ endColumn: 8,
+ messageId: "unexpectedWhitespace",
+ data: { type: "spread" },
+ type: "SpreadElement"
+ }]
+ },
+ {
+ code: "fn(... args)",
+ output: "fn(...args)",
+ errors: [{
+ line: 1,
+ column: 7,
+ endLine: 1,
+ endColumn: 9,
messageId: "unexpectedWhitespace",
data: { type: "spread" },
type: "SpreadElement"
errors: [{
line: 1,
column: 7,
+ endLine: 1,
+ endColumn: 8,
+ messageId: "unexpectedWhitespace",
+ data: { type: "spread" },
+ type: "SpreadElement"
+ }]
+ },
+ {
+ code: "fn(... \t args)",
+ output: "fn(...args)",
+ errors: [{
+ line: 1,
+ column: 7,
+ endLine: 1,
+ endColumn: 10,
messageId: "unexpectedWhitespace",
data: { type: "spread" },
type: "SpreadElement"
errors: [{
line: 1,
column: 7,
+ endLine: 2,
+ endColumn: 1,
+ messageId: "unexpectedWhitespace",
+ data: { type: "spread" },
+ type: "SpreadElement"
+ }]
+ },
+ {
+ code: "fn(...\n args)",
+ output: "fn(...args)",
+ errors: [{
+ line: 1,
+ column: 7,
+ endLine: 2,
+ endColumn: 5,
+ messageId: "unexpectedWhitespace",
+ data: { type: "spread" },
+ type: "SpreadElement"
+ }]
+ },
+ {
+ code: "fn(...\n\targs)",
+ output: "fn(...args)",
+ errors: [{
+ line: 1,
+ column: 7,
+ endLine: 2,
+ endColumn: 2,
messageId: "unexpectedWhitespace",
data: { type: "spread" },
type: "SpreadElement"
errors: [{
line: 1,
column: 7,
+ endLine: 1,
+ endColumn: 8,
messageId: "unexpectedWhitespace",
data: { type: "spread" },
type: "SpreadElement"
errors: [{
line: 1,
column: 7,
+ endLine: 1,
+ endColumn: 8,
messageId: "unexpectedWhitespace",
data: { type: "spread" },
type: "SpreadElement"
errors: [{
line: 1,
column: 7,
+ endLine: 2,
+ endColumn: 1,
messageId: "unexpectedWhitespace",
data: { type: "spread" },
type: "SpreadElement"
options: ["always"],
errors: [{
line: 1,
- column: 7,
+ column: 4,
+ endLine: 1,
+ endColumn: 7,
messageId: "expectedWhitespace",
data: { type: "spread" },
type: "SpreadElement"
errors: [{
line: 1,
column: 7,
+ endLine: 1,
+ endColumn: 8,
messageId: "unexpectedWhitespace",
data: { type: "spread" },
type: "SpreadElement"
errors: [{
line: 1,
column: 7,
+ endLine: 1,
+ endColumn: 8,
messageId: "unexpectedWhitespace",
data: { type: "spread" },
type: "SpreadElement"
options: ["always"],
errors: [{
line: 1,
- column: 7,
+ column: 4,
+ endLine: 1,
+ endColumn: 7,
messageId: "expectedWhitespace",
data: { type: "spread" },
type: "SpreadElement"
options: ["always"],
errors: [{
line: 1,
- column: 7,
+ column: 4,
+ endLine: 1,
+ endColumn: 7,
messageId: "expectedWhitespace",
data: { type: "spread" },
type: "SpreadElement"
errors: [{
line: 1,
column: 5,
+ endLine: 1,
+ endColumn: 6,
messageId: "unexpectedWhitespace",
data: { type: "spread" },
type: "SpreadElement"
errors: [{
line: 1,
column: 5,
+ endLine: 1,
+ endColumn: 6,
messageId: "unexpectedWhitespace",
data: { type: "spread" },
type: "SpreadElement"
errors: [{
line: 1,
column: 5,
+ endLine: 2,
+ endColumn: 1,
messageId: "unexpectedWhitespace",
data: { type: "spread" },
type: "SpreadElement"
errors: [{
line: 1,
column: 5,
+ endLine: 1,
+ endColumn: 6,
messageId: "unexpectedWhitespace",
data: { type: "spread" },
type: "SpreadElement"
errors: [{
line: 1,
column: 5,
+ endLine: 1,
+ endColumn: 6,
messageId: "unexpectedWhitespace",
data: { type: "spread" },
type: "SpreadElement"
errors: [{
line: 1,
column: 5,
+ endLine: 2,
+ endColumn: 1,
messageId: "unexpectedWhitespace",
data: { type: "spread" },
type: "SpreadElement"
options: ["always"],
errors: [{
line: 1,
- column: 5,
+ column: 2,
+ endLine: 1,
+ endColumn: 5,
messageId: "expectedWhitespace",
data: { type: "spread" },
type: "SpreadElement"
errors: [{
line: 1,
column: 5,
+ endLine: 1,
+ endColumn: 6,
messageId: "unexpectedWhitespace",
data: { type: "spread" },
type: "SpreadElement"
errors: [{
line: 1,
column: 5,
+ endLine: 1,
+ endColumn: 6,
messageId: "unexpectedWhitespace",
data: { type: "spread" },
type: "SpreadElement"
options: ["always"],
errors: [{
line: 1,
- column: 5,
+ column: 2,
+ endLine: 1,
+ endColumn: 5,
messageId: "expectedWhitespace",
data: { type: "spread" },
type: "SpreadElement"
options: ["always"],
errors: [{
line: 1,
- column: 5,
+ column: 2,
+ endLine: 1,
+ endColumn: 5,
messageId: "expectedWhitespace",
data: { type: "spread" },
type: "SpreadElement"
errors: [{
line: 1,
column: 15,
+ endLine: 1,
+ endColumn: 16,
messageId: "unexpectedWhitespace",
data: { type: "rest" },
type: "RestElement"
errors: [{
line: 1,
column: 15,
+ endLine: 1,
+ endColumn: 16,
messageId: "unexpectedWhitespace",
data: { type: "rest" },
type: "RestElement"
errors: [{
line: 1,
column: 15,
+ endLine: 2,
+ endColumn: 1,
messageId: "unexpectedWhitespace",
data: { type: "rest" },
type: "RestElement"
errors: [{
line: 1,
column: 15,
+ endLine: 1,
+ endColumn: 16,
messageId: "unexpectedWhitespace",
data: { type: "rest" },
type: "RestElement"
errors: [{
line: 1,
column: 15,
+ endLine: 1,
+ endColumn: 16,
messageId: "unexpectedWhitespace",
data: { type: "rest" },
type: "RestElement"
errors: [{
line: 1,
column: 15,
+ endLine: 2,
+ endColumn: 1,
messageId: "unexpectedWhitespace",
data: { type: "rest" },
type: "RestElement"
options: ["always"],
errors: [{
line: 1,
- column: 15,
+ column: 12,
+ endLine: 1,
+ endColumn: 15,
messageId: "expectedWhitespace",
data: { type: "rest" },
type: "RestElement"
errors: [{
line: 1,
column: 20,
+ endLine: 1,
+ endColumn: 21,
messageId: "unexpectedWhitespace",
data: { type: "spread property" },
type: "SpreadElement"
errors: [{
line: 1,
column: 20,
+ endLine: 1,
+ endColumn: 21,
messageId: "unexpectedWhitespace",
data: { type: "spread property" },
type: "SpreadElement"
errors: [{
line: 1,
column: 20,
+ endLine: 2,
+ endColumn: 1,
messageId: "unexpectedWhitespace",
data: { type: "spread property" },
type: "SpreadElement"
errors: [{
line: 1,
column: 20,
+ endLine: 1,
+ endColumn: 21,
messageId: "unexpectedWhitespace",
data: { type: "spread property" },
type: "SpreadElement"
errors: [{
line: 1,
column: 20,
+ endLine: 1,
+ endColumn: 21,
messageId: "unexpectedWhitespace",
data: { type: "spread property" },
type: "SpreadElement"
errors: [{
line: 1,
column: 20,
+ endLine: 2,
+ endColumn: 1,
messageId: "unexpectedWhitespace",
data: { type: "spread property" },
type: "SpreadElement"
parserOptions: { ecmaVersion: 2018 },
errors: [{
line: 1,
- column: 20,
+ column: 17,
+ endLine: 1,
+ endColumn: 20,
messageId: "expectedWhitespace",
data: { type: "spread property" },
type: "SpreadElement"
errors: [{
line: 1,
column: 20,
+ endLine: 1,
+ endColumn: 21,
messageId: "unexpectedWhitespace",
data: { type: "spread property" },
type: "SpreadElement"
errors: [{
line: 1,
column: 20,
+ endLine: 1,
+ endColumn: 21,
messageId: "unexpectedWhitespace",
data: { type: "spread property" },
type: "SpreadElement"
parserOptions: { ecmaVersion: 2018 },
errors: [{
line: 1,
- column: 20,
+ column: 17,
+ endLine: 1,
+ endColumn: 20,
messageId: "expectedWhitespace",
data: { type: "spread property" },
type: "SpreadElement"
parserOptions: { ecmaVersion: 2018 },
errors: [{
line: 1,
- column: 20,
+ column: 17,
+ endLine: 1,
+ endColumn: 20,
messageId: "expectedWhitespace",
data: { type: "spread property" },
type: "SpreadElement"
errors: [{
line: 1,
column: 16,
+ endLine: 1,
+ endColumn: 17,
messageId: "unexpectedWhitespace",
data: { type: "rest property" },
type: "RestElement"
errors: [{
line: 1,
column: 16,
+ endLine: 1,
+ endColumn: 17,
messageId: "unexpectedWhitespace",
data: { type: "rest property" },
type: "RestElement"
errors: [{
line: 1,
column: 16,
+ endLine: 2,
+ endColumn: 1,
messageId: "unexpectedWhitespace",
data: { type: "rest property" },
type: "RestElement"
errors: [{
line: 1,
column: 16,
+ endLine: 1,
+ endColumn: 17,
messageId: "unexpectedWhitespace",
data: { type: "rest property" },
type: "RestElement"
errors: [{
line: 1,
column: 16,
+ endLine: 1,
+ endColumn: 17,
messageId: "unexpectedWhitespace",
data: { type: "rest property" },
type: "RestElement"
errors: [{
line: 1,
column: 16,
+ endLine: 2,
+ endColumn: 1,
messageId: "unexpectedWhitespace",
data: { type: "rest property" },
type: "RestElement"
parserOptions: { ecmaVersion: 2018 },
errors: [{
line: 1,
- column: 16,
+ column: 13,
+ endLine: 1,
+ endColumn: 16,
messageId: "expectedWhitespace",
data: { type: "rest property" },
type: "RestElement"
{ code: "for ( var i = 0;i < results.length; ) {}", options: [{ after: false }] }
],
invalid: [
+ {
+ code: "var a = 'b' ;",
+ output: "var a = 'b';",
+ errors: [
+ {
+ messageId: "unexpectedWhitespaceBefore",
+ type: "VariableDeclaration",
+ line: 1,
+ column: 12,
+ endLine: 1,
+ endColumn: 14
+ }
+ ]
+ },
{
code: "var a = 'b' ;",
output: "var a = 'b';",
- errors: [{ messageId: "unexpectedWhitespaceBefore", type: "VariableDeclaration", line: 1, column: 13 }]
+ errors: [
+ {
+ messageId: "unexpectedWhitespaceBefore",
+ type: "VariableDeclaration",
+ line: 1,
+ column: 12,
+ endLine: 1,
+ endColumn: 13
+ }
+ ]
},
{
code: "var a = 'b',\nc = 'd' ;",
output: "var a = 'b',\nc = 'd';",
- errors: [{ messageId: "unexpectedWhitespaceBefore", type: "VariableDeclaration", line: 2, column: 9 }]
+ errors: [{ messageId: "unexpectedWhitespaceBefore", type: "VariableDeclaration", line: 2, column: 8 }]
},
{
code: "var a = function() {} ;",
output: "var a = function() {};",
- errors: [{ messageId: "unexpectedWhitespaceBefore", type: "VariableDeclaration", line: 1, column: 23 }]
+ errors: [{ messageId: "unexpectedWhitespaceBefore", type: "VariableDeclaration", line: 1, column: 22 }]
},
{
code: "var a = function() {\n} ;",
output: "var a = function() {\n};",
- errors: [{ messageId: "unexpectedWhitespaceBefore", type: "VariableDeclaration", line: 2, column: 3 }]
+ errors: [{ messageId: "unexpectedWhitespaceBefore", type: "VariableDeclaration", line: 2, column: 2 }]
},
{
code: "/^a$/.test('b') ;",
output: "/^a$/.test('b');",
- errors: [{ messageId: "unexpectedWhitespaceBefore", type: "ExpressionStatement", line: 1, column: 17 }]
+ errors: [{ messageId: "unexpectedWhitespaceBefore", type: "ExpressionStatement", line: 1, column: 16 }]
},
{
code: ";(function(){}()) ;",
output: ";(function(){}());",
- errors: [{ messageId: "unexpectedWhitespaceBefore", type: "ExpressionStatement", line: 1, column: 19 }]
+ errors: [{ messageId: "unexpectedWhitespaceBefore", type: "ExpressionStatement", line: 1, column: 18 }]
},
{
code: "while (true) { break ; }",
output: "while (true) { break; }",
- errors: [{ messageId: "unexpectedWhitespaceBefore", type: "BreakStatement", line: 1, column: 22 }]
+ errors: [{ messageId: "unexpectedWhitespaceBefore", type: "BreakStatement", line: 1, column: 21 }]
},
{
code: "while (true) { continue ; }",
output: "while (true) { continue; }",
- errors: [{ messageId: "unexpectedWhitespaceBefore", type: "ContinueStatement", line: 1, column: 25 }]
+ errors: [{ messageId: "unexpectedWhitespaceBefore", type: "ContinueStatement", line: 1, column: 24 }]
},
{
code: "debugger ;",
output: "debugger;",
- errors: [{ messageId: "unexpectedWhitespaceBefore", type: "DebuggerStatement", line: 1, column: 10 }]
+ errors: [{ messageId: "unexpectedWhitespaceBefore", type: "DebuggerStatement", line: 1, column: 9 }]
},
{
code: "function foo() { return ; }",
output: "function foo() { return; }",
- errors: [{ messageId: "unexpectedWhitespaceBefore", type: "ReturnStatement", line: 1, column: 25 }]
+ errors: [{ messageId: "unexpectedWhitespaceBefore", type: "ReturnStatement", line: 1, column: 24 }]
},
{
code: "throw new Error('foo') ;",
output: "throw new Error('foo');",
- errors: [{ messageId: "unexpectedWhitespaceBefore", type: "ThrowStatement", line: 1, column: 24 }]
+ errors: [{ messageId: "unexpectedWhitespaceBefore", type: "ThrowStatement", line: 1, column: 23 }]
},
{
code: "for (var i = 0 ; i < 10 ; i++) {}",
output: "for (var i = 0; i < 10; i++) {}",
errors: [
- { messageId: "unexpectedWhitespaceBefore", type: "ForStatement", line: 1, column: 16 },
- { messageId: "unexpectedWhitespaceBefore", type: "ForStatement", line: 1, column: 25 }
+ { messageId: "unexpectedWhitespaceBefore", type: "ForStatement", line: 1, column: 15 },
+ { messageId: "unexpectedWhitespaceBefore", type: "ForStatement", line: 1, column: 24 }
]
},
{
code: "var a = 'b';c = 'd';",
output: "var a = 'b'; c = 'd';",
- errors: [{ messageId: "missingWhitespaceAfter", type: "VariableDeclaration", line: 1, column: 12 }]
+ errors: [
+ {
+ messageId: "missingWhitespaceAfter",
+ type: "VariableDeclaration",
+ line: 1,
+ column: 12,
+ endLine: 1,
+ endColumn: 13
+ }
+ ]
},
{
code: "var a = 'b';",
output: "var a = 'b' ;",
options: [{ before: true, after: true }],
- errors: [{ messageId: "missingWhitespaceBefore", type: "VariableDeclaration", line: 1, column: 12 }]
+ errors: [
+ {
+ messageId: "missingWhitespaceBefore",
+ type: "VariableDeclaration",
+ line: 1,
+ column: 12,
+ endLine: 1,
+ endColumn: 13
+ }
+ ]
},
{
code: "var a = 'b'; c = 'd';",
output: "var a = 'b';c = 'd';",
options: [{ before: false, after: false }],
- errors: [{ messageId: "unexpectedWhitespaceAfter", type: "VariableDeclaration", line: 1, column: 12 }]
+ errors: [
+ {
+ messageId: "unexpectedWhitespaceAfter",
+ type: "VariableDeclaration",
+ line: 1,
+ column: 13,
+ endLine: 1,
+ endColumn: 14
+ }
+ ]
+ },
+ {
+ code: "var a = 'b'; c = 'd';",
+ output: "var a = 'b';c = 'd';",
+ options: [{ before: false, after: false }],
+ errors: [
+ {
+ messageId: "unexpectedWhitespaceAfter",
+ type: "VariableDeclaration",
+ line: 1,
+ column: 13,
+ endLine: 1,
+ endColumn: 16
+ }
+ ]
},
{
code: "for (var i = 0;i < 10;i++) {}",
output: "for (var i = 0; i < 10; i++) {}",
errors: [
- { messageId: "missingWhitespaceAfter", type: "ForStatement", line: 1, column: 15 },
- { messageId: "missingWhitespaceAfter", type: "ForStatement", line: 1, column: 22 }
+ {
+ messageId: "missingWhitespaceAfter",
+ type: "ForStatement",
+ line: 1,
+ column: 15,
+ endLine: 1,
+ endColumn: 16
+ },
+ {
+ messageId: "missingWhitespaceAfter",
+ type: "ForStatement",
+ line: 1,
+ column: 22,
+ endLine: 1,
+ endColumn: 23
+ }
]
},
{
output: "for (var i = 0 ; i < 10 ; i++) {}",
options: [{ before: true, after: true }],
errors: [
- { messageId: "missingWhitespaceBefore", type: "ForStatement", line: 1, column: 15 },
- { messageId: "missingWhitespaceBefore", type: "ForStatement", line: 1, column: 23 }
+ {
+ messageId: "missingWhitespaceBefore",
+ type: "ForStatement",
+ line: 1,
+ column: 15,
+ endLine: 1,
+ endColumn: 16
+ },
+ {
+ messageId: "missingWhitespaceBefore",
+ type: "ForStatement",
+ line: 1,
+ column: 23,
+ endLine: 1,
+ endColumn: 24
+ }
]
},
{
output: "for (var i = 0;i < 10;i++) {}",
options: [{ before: false, after: false }],
errors: [
- { messageId: "unexpectedWhitespaceAfter", type: "ForStatement", line: 1, column: 15 },
- { messageId: "unexpectedWhitespaceAfter", type: "ForStatement", line: 1, column: 23 }
+ { messageId: "unexpectedWhitespaceAfter", type: "ForStatement", line: 1, column: 16 },
+ { messageId: "unexpectedWhitespaceAfter", type: "ForStatement", line: 1, column: 24 }
]
},
{
options: [{ before: false, after: true }],
parserOptions: { ecmaVersion: 6, sourceType: "module" },
errors: [
- { messageId: "unexpectedWhitespaceBefore", type: "ImportDeclaration", line: 1, column: 23 }
+ { messageId: "unexpectedWhitespaceBefore", type: "ImportDeclaration", line: 1, column: 22 }
]
},
{
options: [{ before: false, after: true }],
parserOptions: { ecmaVersion: 6, sourceType: "module" },
errors: [
- { messageId: "unexpectedWhitespaceBefore", type: "ImportDeclaration", line: 1, column: 28 }
+ { messageId: "unexpectedWhitespaceBefore", type: "ImportDeclaration", line: 1, column: 27 }
]
},
{
options: [{ before: false, after: true }],
parserOptions: { ecmaVersion: 6, sourceType: "module" },
errors: [
- { messageId: "unexpectedWhitespaceBefore", type: "ExportNamedDeclaration", line: 1, column: 27 }
+ { messageId: "unexpectedWhitespaceBefore", type: "ExportNamedDeclaration", line: 1, column: 26 }
]
},
{
options: [{ before: false, after: true }],
parserOptions: { ecmaVersion: 6, sourceType: "module" },
errors: [
- { messageId: "unexpectedWhitespaceBefore", type: "ExportAllDeclaration", line: 1, column: 21 }
+ { messageId: "unexpectedWhitespaceBefore", type: "ExportAllDeclaration", line: 1, column: 20 }
]
},
{
options: [{ before: false, after: true }],
parserOptions: { ecmaVersion: 6, sourceType: "module" },
errors: [
- { messageId: "unexpectedWhitespaceBefore", type: "ExportDefaultDeclaration", line: 1, column: 20 }
+ { messageId: "unexpectedWhitespaceBefore", type: "ExportDefaultDeclaration", line: 1, column: 19 }
+ ]
+ },
+ {
+ code: "while(foo) {continue ;}",
+ output: "while(foo) {continue;}",
+ options: [{ before: false, after: true }],
+ parserOptions: { ecmaVersion: 6 },
+ errors: [
+ {
+ messageId: "unexpectedWhitespaceBefore",
+ type: "ContinueStatement",
+ line: 1,
+ column: 21,
+ endLine: 1,
+ endColumn: 24
+ }
+ ]
+ },
+ {
+ code: "if(foo) {throw new Error() ; }",
+ output: "if(foo) {throw new Error(); }",
+ options: [{ before: false, after: false }],
+ parserOptions: { ecmaVersion: 6 },
+ errors: [
+ {
+ messageId: "unexpectedWhitespaceBefore",
+ type: "ThrowStatement",
+ line: 1,
+ column: 27,
+ endLine: 1,
+ endColumn: 30
+ }
+ ]
+ },
+ {
+ code: "for(a ; ; );",
+ output: "for(a;; );",
+ options: [{ before: false, after: false }],
+ parserOptions: { ecmaVersion: 6 },
+ errors: [{
+ type: "ForStatement",
+ messageId: "unexpectedWhitespaceBefore",
+ line: 1,
+ column: 6,
+ endLine: 1,
+ endColumn: 7
+ },
+ {
+ type: "ForStatement",
+ messageId: "unexpectedWhitespaceAfter",
+ line: 1,
+ column: 8,
+ endLine: 1,
+ endColumn: 9
+ }]
+ },
+ {
+ code: "for(a ; \n ; );",
+ output: "for(a; \n ; );",
+ options: [{ before: false, after: false }],
+ parserOptions: { ecmaVersion: 6 },
+ errors: [{
+ type: "ForStatement",
+ messageId: "unexpectedWhitespaceBefore",
+ line: 1,
+ column: 6,
+ endLine: 1,
+ endColumn: 7
+ }
]
}
]
endColumn: 1
}]
},
+ {
+ code: "foo()\r\n",
+ output: "foo();\r\n",
+ errors: [{
+ messageId: "missingSemi",
+ type: "ExpressionStatement",
+ column: 6,
+ endLine: 2,
+ endColumn: 1
+ }]
+ },
{
code: "foo()\nbar();",
output: "foo();\nbar();",
endColumn: 1
}]
},
+ {
+ code: "foo()\r\nbar();",
+ output: "foo();\r\nbar();",
+ errors: [{
+ messageId: "missingSemi",
+ type: "ExpressionStatement",
+ column: 6,
+ endLine: 2,
+ endColumn: 1
+ }]
+ },
{
code: "for (var a in b) var i ",
output: "for (var a in b) var i; ",
});
describe("getNextLocation", () => {
- const code = "foo;\n";
- const ast = espree.parse(code, ESPREE_CONFIG);
- const sourceCode = new SourceCode(code, ast);
-
- it("should handle normal case", () => {
- assert.deepStrictEqual(
- astUtils.getNextLocation(
- sourceCode,
- { line: 1, column: 0 }
- ),
- { line: 1, column: 1 }
- );
- });
- it("should handle linebreaks", () => {
- assert.deepStrictEqual(
- astUtils.getNextLocation(
- sourceCode,
- { line: 1, column: 4 }
- ),
- { line: 2, column: 0 }
- );
- });
+ /* eslint-disable quote-props */
+ const expectedResults = {
+ "": [[1, 0], null],
+ "\n": [[1, 0], [2, 0], null],
+ "\r\n": [[1, 0], [2, 0], null],
+ "foo": [[1, 0], [1, 1], [1, 2], [1, 3], null],
+ "foo\n": [[1, 0], [1, 1], [1, 2], [1, 3], [2, 0], null],
+ "foo\r\n": [[1, 0], [1, 1], [1, 2], [1, 3], [2, 0], null],
+ "foo;\n": [[1, 0], [1, 1], [1, 2], [1, 3], [1, 4], [2, 0], null],
+ "a\nb": [[1, 0], [1, 1], [2, 0], [2, 1], null],
+ "a\nb\n": [[1, 0], [1, 1], [2, 0], [2, 1], [3, 0], null],
+ "a\r\nb\r\n": [[1, 0], [1, 1], [2, 0], [2, 1], [3, 0], null],
+ "a\nb\r\n": [[1, 0], [1, 1], [2, 0], [2, 1], [3, 0], null],
+ "a\n\n": [[1, 0], [1, 1], [2, 0], [3, 0], null],
+ "a\r\n\r\n": [[1, 0], [1, 1], [2, 0], [3, 0], null],
+ "\n\r\n\n\r\n": [[1, 0], [2, 0], [3, 0], [4, 0], [5, 0], null],
+ "ab\u2029c": [[1, 0], [1, 1], [1, 2], [2, 0], [2, 1], null],
+ "ab\ncde\n": [[1, 0], [1, 1], [1, 2], [2, 0], [2, 1], [2, 2], [2, 3], [3, 0], null],
+ "a ": [[1, 0], [1, 1], [1, 2], null],
+ "a\t": [[1, 0], [1, 1], [1, 2], null],
+ "a \n": [[1, 0], [1, 1], [1, 2], [2, 0], null]
+ };
+ /* eslint-enable quote-props */
- it("should return null when result is out of bound", () => {
- assert.strictEqual(
- astUtils.getNextLocation(
- sourceCode,
- { line: 2, column: 0 }
- ),
- null
- );
+ Object.keys(expectedResults).forEach(code => {
+ it(`should return expected locations for "${code}".`, () => {
+ const ast = espree.parse(code, ESPREE_CONFIG);
+ const sourceCode = new SourceCode(code, ast);
+ const locations = expectedResults[code];
+
+ for (let i = 0; i < locations.length - 1; i++) {
+ const location = { line: locations[i][0], column: locations[i][1] };
+ const expectedNextLocation = locations[i + 1]
+ ? { line: locations[i + 1][0], column: locations[i + 1][1] }
+ : null;
+
+ assert.deepStrictEqual(
+ astUtils.getNextLocation(sourceCode, location),
+ expectedNextLocation
+ );
+ }
+ });
});
});
"no-lone-blocks": "suggestion",
"no-lonely-if": "suggestion",
"no-loop-func": "suggestion",
+ "no-loss-of-precision": "problem",
"no-magic-numbers": "suggestion",
"no-misleading-character-class": "problem",
"no-mixed-operators": "suggestion",
"wrap-regex": "layout",
"yield-star-spacing": "layout",
"yoda": "suggestion"
-}
+}
\ No newline at end of file