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 global modifier to naming-convention #2691

Conversation

jharwig
Copy link

@jharwig jharwig commented Oct 20, 2020

Fixes #2318

Added a new global modifier to the naming-convention rule. This is only valid for variable selectors with the const modifier. It allows for configuring top-level/global constants differently than constants defined inside nested function scopes.

Something to look at is the naming of global. The issue describes topLevel as another possible name. Another is whether this global modifier should be valid for function selectors (it is not in this PR.)

The implementation was based on the description of this comment in the issue

@typescript-eslint
Copy link
Contributor

Thanks for the PR, @jharwig!

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.

@codecov
Copy link

codecov bot commented Oct 20, 2020

Codecov Report

Merging #2691 into master will increase coverage by 0.02%.
The diff coverage is 100.00%.

@@            Coverage Diff             @@
##           master    #2691      +/-   ##
==========================================
+ Coverage   92.79%   92.81%   +0.02%     
==========================================
  Files         294      294              
  Lines        9682     9686       +4     
  Branches     2717     2718       +1     
==========================================
+ Hits         8984     8990       +6     
+ Misses        330      329       -1     
+ Partials      368      367       -1     
Flag Coverage Δ
#unittest 92.81% <100.00%> (+0.02%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

Impacted Files Coverage Δ
...kages/eslint-plugin/src/rules/naming-convention.ts 89.94% <100.00%> (+0.64%) ⬆️

@bradzacher bradzacher added the enhancement: plugin rule option New rule option for an existing eslint-plugin rule label Oct 20, 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.

code itself LGTM - just two comments on the tests - thanks for your work!

const localConstant = 2;
}
`,
parserOptions,
Copy link
Member

Choose a reason for hiding this comment

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

nit - you don't need to use the parserOptions here, and instead should do:

Suggested change
parserOptions,
parserOptions: {
sourceType: 'script',
},

Copy link
Member

Choose a reason for hiding this comment

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

Additionally, please duplicate this test case and additionally use sourceType: 'module' to ensure both scripts and modules work as expected.

@bradzacher
Copy link
Member

Closing in favour of #2802

@bradzacher bradzacher closed this Nov 24, 2020
@github-actions github-actions bot locked as resolved and limited conversation to collaborators Dec 25, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
awaiting response Issues waiting for a reply from the OP or another party enhancement: plugin rule option New rule option for an existing eslint-plugin rule
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[naming-convention] modifier global - Allow selecting only global variables
2 participants