Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(eslint-plugin): add extension rule keyword-spacing #1739

Merged
merged 32 commits into from Apr 20, 2020
Merged

feat(eslint-plugin): add extension rule keyword-spacing #1739

merged 32 commits into from Apr 20, 2020

Conversation

OoDeLally
Copy link
Contributor

@OoDeLally OoDeLally commented Mar 16, 2020

Addressing my own issue
fixes #1729

I am totally new to this, so feel free to suggest me improvements.

@typescript-eslint
Copy link
Contributor

Thanks for the PR, @OoDeLally!

typescript-eslint is a 100% community driven project, and we are incredibly grateful that you are contributing to that community.

The core maintainers work on this in their personal time, so please understand that it may not be possible for them to review your work immediately.

Thanks again!


🙏 Please, if you or your company is finding typescript-eslint valuable, help us sustain the project by sponsoring it transparently on https://opencollective.com/typescript-eslint. As a thank you, your profile/company logo will be added to our main README which receives thousands of unique visitors per day.

@OoDeLally OoDeLally changed the title feat(eslint-plugin) keyword-spacing feat(eslint-plugin) Add rule keyword-spacing Mar 16, 2020
Copy link
Contributor

@G-Rath G-Rath left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I've just done a basic lookover, focusing on your comments to help unblock you until someone can do a proper review :)

Happy to help if you have questions!

packages/eslint-plugin/package.json Outdated Show resolved Hide resolved
packages/eslint-plugin/src/rules/keyword-spacing.ts Outdated Show resolved Hide resolved
packages/eslint-plugin/src/rules/keyword-spacing.ts Outdated Show resolved Hide resolved
packages/eslint-plugin/tests/rules/keyword-spacing.test.ts Outdated Show resolved Hide resolved
@bradzacher bradzacher added the enhancement: new base rule extension New base rule extension required to handle a TS specific case label Mar 16, 2020
@OoDeLally
Copy link
Contributor Author

@G-Rath Ok, thanks for your comments. I'm now importing the base rule, it simplifies a bit.

Copy link
Contributor

@G-Rath G-Rath left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looking good!

Now that you're using the base rule, you can also drop the majority of the tests, since we don't need to re-test what eslint has already tested 😉

packages/eslint-plugin/typings/eslint-rules.d.ts Outdated Show resolved Hide resolved
packages/eslint-plugin/src/rules/keyword-spacing.ts Outdated Show resolved Hide resolved
packages/eslint-plugin/src/rules/keyword-spacing.ts Outdated Show resolved Hide resolved
packages/eslint-plugin/src/rules/keyword-spacing.ts Outdated Show resolved Hide resolved
@OoDeLally
Copy link
Contributor Author

I'm now re-declaring the list of keywords both in typing and in string array.

@OoDeLally
Copy link
Contributor Author

What is the deal with Semantic Pull Request? What is wrong with my title?

@OoDeLally
Copy link
Contributor Author

How is that codecov thingy actionable? Anything I should do about it?

@bradzacher bradzacher changed the title feat(eslint-plugin) Add rule keyword-spacing feat(eslint-plugin): Add rule keyword-spacing Mar 17, 2020
@bradzacher
Copy link
Member

bradzacher commented Mar 17, 2020

What is the deal with Semantic Pull Request? What is wrong with my title?

You were missing a : after your ). I updated appropriately.

How is that codecov thingy actionable? Anything I should do about it?

If you click through to the details on the codecov site, it'll show you what branches of your code have not been hit by tests.
i.e. clicking on the keyword-spacing.ts file in the codecov comment takes you here: https://codecov.io/gh/typescript-eslint/typescript-eslint/pull/1739/diff?src=pr&el=tree#diff-cGFja2FnZXMvZXNsaW50LXBsdWdpbi9zcmMvcnVsZXMva2V5d29yZC1zcGFjaW5nLnRz

Scrolling through that report, green means all good, yellow means one of the branches was missed, and red means all of the branches were missed.
I.e. looking at the report, theres missed lines for reporting expectedAfter and unexpectedAfter.

packages/eslint-plugin/src/util/astUtils.ts Outdated Show resolved Hide resolved
packages/eslint-plugin/typings/eslint-keywords.d.ts Outdated Show resolved Hide resolved
@OoDeLally
Copy link
Contributor Author

Would you know a way to avoid having to declare the option typing twice (in eslint-rule.d.ts and in keyword-spacing.ts) ?
I see no way of declaring it at one place and import them from the other place. Tried many ways, without success.

Copy link
Member

@bradzacher bradzacher left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

a few comments, you might be able to simplify this by being a bit hacky - see my last comment.

packages/eslint-plugin/src/rules/keyword-spacing.ts Outdated Show resolved Hide resolved
packages/eslint-plugin/typings/eslint-rules.d.ts Outdated Show resolved Hide resolved
packages/eslint-plugin/src/rules/keyword-spacing.ts Outdated Show resolved Hide resolved
packages/eslint-plugin/src/rules/keyword-spacing.ts Outdated Show resolved Hide resolved
@bradzacher bradzacher added the awaiting response Issues waiting for a reply from the OP or another party label Apr 12, 2020
@codecov
Copy link

codecov bot commented Apr 12, 2020

Codecov Report

Merging #1739 into master will increase coverage by 0.00%.
The diff coverage is 100.00%.

@@           Coverage Diff           @@
##           master    #1739   +/-   ##
=======================================
  Coverage   94.37%   94.38%           
=======================================
  Files         164      165    +1     
  Lines        7572     7585   +13     
  Branches     2175     2175           
=======================================
+ Hits         7146     7159   +13     
  Misses        183      183           
  Partials      243      243           
Flag Coverage Δ
#unittest 94.38% <100.00%> (+<0.01%) ⬆️
Impacted Files Coverage Δ
...ackages/eslint-plugin/src/rules/keyword-spacing.ts 100.00% <100.00%> (ø)

@OoDeLally
Copy link
Contributor Author

OoDeLally commented Apr 12, 2020

Looking at the rule's source code, you might be able to get away with just this fudge code for this extension:

This seems to fail every test with:

  ● keyword-spacing › invalid › const foo = {}as {}

    TypeError: Cannot read property 'before' of undefined
    Occurred while linting file.ts:1

      at checkSpacingBefore (../../node_modules/eslint/lib/rules/keyword-spacing.js:268:21)
      at Object.checkSpacingForImportNamespaceSpecifier [as ImportNamespaceSpecifier] (../../node_modules/eslint/lib/rules/keyword-spacing.js:466:13)
      at TSAsExpression (src/rules/keyword-spacing.ts:3054:19)

The error is in lib/rules/keyword-spacing.js at

        function checkSpacingBefore(token, pattern) {
            checkMethodMap[token.value].before(token, pattern || PREV_TOKEN);
        }

I don't really understand what is going on, so I wouldn't risk replacing it.

If you find a way to make it work, I'll be happy to simplify it.

@bradzacher bradzacher removed the awaiting response Issues waiting for a reply from the OP or another party label Apr 13, 2020
Copy link
Member

@bradzacher bradzacher left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks!

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
enhancement: new base rule extension New base rule extension required to handle a TS specific case
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[keyword-spacing] Require space before / after as
3 participants