-
Notifications
You must be signed in to change notification settings - Fork 12
host: Remove Monaco Percy snapshots and add lint rule #3961
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
Merged
Merged
Changes from all commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
750da6f
host: Remove Monaco Percy snapshots
backspace 08beb33
Add empty commit
backspace 5237b04
Add lint rule about percySnapshot import
backspace 42ea52e
Add exception for override import
backspace 57adac4
Remove unused import
backspace f5fc6ea
Fix import
backspace 233b4d5
Add empty commit
backspace File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
43 changes: 43 additions & 0 deletions
43
packages/eslint-plugin-boxel/lib/rules/no-percy-direct-import.js
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,43 @@ | ||
| 'use strict'; | ||
|
|
||
| //------------------------------------------------------------------------------ | ||
| // Rule Definition | ||
| //------------------------------------------------------------------------------ | ||
|
|
||
| /** @type {import('eslint').Rule.RuleModule} */ | ||
| module.exports = { | ||
| meta: { | ||
| type: 'problem', | ||
| docs: { | ||
| description: | ||
| 'Forbid importing percySnapshot directly from @percy/ember; use @cardstack/host/tests/helpers instead', | ||
| category: 'Best Practices', | ||
| recommended: true, | ||
| }, | ||
| fixable: 'code', | ||
| schema: [], | ||
| messages: { | ||
| noPercyDirectImport: | ||
| "Do not import directly from '@percy/ember'. Use `import { percySnapshot } from '@cardstack/host/tests/helpers'` instead.", | ||
| }, | ||
| }, | ||
|
|
||
| create(context) { | ||
| return { | ||
| ImportDeclaration(node) { | ||
| if (node.source.value === '@percy/ember') { | ||
| context.report({ | ||
| node, | ||
| messageId: 'noPercyDirectImport', | ||
| fix(fixer) { | ||
| return fixer.replaceText( | ||
| node, | ||
| "import { percySnapshot } from '@cardstack/host/tests/helpers';", | ||
| ); | ||
| }, | ||
| }); | ||
| } | ||
| }, | ||
| }; | ||
| }, | ||
| }; | ||
42 changes: 42 additions & 0 deletions
42
packages/eslint-plugin-boxel/tests/lib/rules/no-percy-direct-import-test.js
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,42 @@ | ||
| 'use strict'; | ||
|
|
||
| //------------------------------------------------------------------------------ | ||
| // Requirements | ||
| //------------------------------------------------------------------------------ | ||
|
|
||
| const rule = require('../../../lib/rules/no-percy-direct-import'); | ||
| const RuleTester = require('eslint').RuleTester; | ||
|
|
||
| //------------------------------------------------------------------------------ | ||
| // Tests | ||
| //------------------------------------------------------------------------------ | ||
|
|
||
| const ruleTester = new RuleTester({ | ||
| parserOptions: { | ||
| ecmaVersion: 2022, | ||
| sourceType: 'module', | ||
| }, | ||
| }); | ||
|
|
||
| ruleTester.run('no-percy-direct-import', rule, { | ||
| valid: [ | ||
| { | ||
| code: `import { percySnapshot } from '@cardstack/host/tests/helpers';`, | ||
| }, | ||
| { | ||
| code: `import { foo } from 'some-other-module';`, | ||
| }, | ||
| ], | ||
| invalid: [ | ||
| { | ||
| code: `import percySnapshot from '@percy/ember';`, | ||
| errors: [{ messageId: 'noPercyDirectImport' }], | ||
| output: `import { percySnapshot } from '@cardstack/host/tests/helpers';`, | ||
| }, | ||
| { | ||
| code: `import { percySnapshot } from '@percy/ember';`, | ||
| errors: [{ messageId: 'noPercyDirectImport' }], | ||
| output: `import { percySnapshot } from '@cardstack/host/tests/helpers';`, | ||
| }, | ||
| ], | ||
| }); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The rule applies to any
ImportDeclarationfrom@percy/ember, but the autofix always replaces the entire import withimport { percySnapshot } .... If a file imports other exports (e.g.,import { foo } from '@percy/ember'orimport * as percy ...), runningeslint --fixwill silently drop those imports and change the binding, leading to runtime errors where the original symbols are used. Consider limiting the fixer to cases that actually importpercySnapshot(default or named), or remove the autofix and only report.Useful? React with 👍 / 👎.