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

Linting: Restrict WordPress import path access #2211

Merged
merged 1 commit into from
Aug 4, 2017
Merged

Conversation

aduth
Copy link
Member

@aduth aduth commented Aug 4, 2017

Related: #941, #929

This pull request seeks to add a lint rule restricting path access for WordPress dependencies. For example:

// Good:
import { keycodes } from '@wordpress/utils';

// Bad:
import { ENTER } from '@wordpress/utils/keycodes';

Implementation notes:

See also:

I found the selectors syntax to not be particularly happy with escaping slashes (\\/) except when using the unicode escape (\\u002F).

Testing instructions:

Verify there are currently no lint issues:

npm run lint

Introduce a lint issue by finding a WordPress dependency and suffixing a path, then re-run the command above and verify the lint issue is surfaced as an error.

@aduth aduth requested a review from nylen August 4, 2017 05:36
@codecov
Copy link

codecov bot commented Aug 4, 2017

Codecov Report

Merging #2211 into master will increase coverage by 0.08%.
The diff coverage is n/a.

Impacted file tree graph

@@            Coverage Diff             @@
##           master    #2211      +/-   ##
==========================================
+ Coverage   23.05%   23.14%   +0.08%     
==========================================
  Files         141      142       +1     
  Lines        4372     4481     +109     
  Branches      739      770      +31     
==========================================
+ Hits         1008     1037      +29     
- Misses       2840     2898      +58     
- Partials      524      546      +22
Impacted Files Coverage Δ
blocks/api/parser.js 96.22% <0%> (-0.92%) ⬇️
editor/index.js 0% <0%> (ø) ⬆️
editor/inserter/index.js 0% <0%> (ø) ⬆️
editor/modes/visual-editor/block-list.js 0% <0%> (ø) ⬆️
blocks/library/text/index.js 41.17% <0%> (ø)
components/button/index.js 93.75% <0%> (+2.84%) ⬆️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 90b16ed...5eef86d. Read the comment docs.

"no-restricted-syntax": [
"error",
{
"selector": "ImportDeclaration[source.value=/^@wordpress\\u002F.+\\u002F/]",
Copy link
Member

Choose a reason for hiding this comment

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

What happens when we begin requiring npm packages like @wordpress/hooks? Path imports should be fine there.

Do we want to match our list of Webpack entry points specifically, or keep this restriction for all @wordpress imports for consistency?

Copy link
Member Author

Choose a reason for hiding this comment

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

The need to traverse into path structure of a dependency is few and far between. I'd be more concerned about all of the places we have this pattern repeated throughout the codebase, particularly if/when we add/remove from the list.

@aduth aduth merged commit e803d00 into master Aug 4, 2017
@aduth aduth deleted the add/lint-wp-deps-path branch August 4, 2017 19:35
ceyhun pushed a commit that referenced this pull request Jun 17, 2020
…ia_to_kotlin

Use Kotlin in react-native-gutenberg-bridge
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants