-
-
Notifications
You must be signed in to change notification settings - Fork 1.5k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Warn for inconsistent import assertions
- Loading branch information
1 parent
518a6d8
commit dc486f3
Showing
8 changed files
with
184 additions
and
36 deletions.
There are no files selected for viewing
This file contains 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 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 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 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
64 changes: 64 additions & 0 deletions
64
test/function/samples/import-assertions/warn-assertion-conflicts/_config.js
This file contains 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,64 @@ | ||
const path = require('path'); | ||
const ID_MAIN = path.join(__dirname, 'main.js'); | ||
|
||
module.exports = { | ||
description: 'warns for conflicting import assertions', | ||
options: { | ||
external: id => id.startsWith('external') | ||
}, | ||
warnings: [ | ||
{ | ||
code: 'INCONSISTENT_IMPORT_ASSERTIONS', | ||
frame: ` | ||
1: import './other.js'; | ||
2: import 'external' assert { type: 'foo' }; | ||
3: import 'external' assert { type: 'bar' }; | ||
^ | ||
4: import 'external'; | ||
5: import('external', { assert: { type: 'baz' } });`, | ||
id: ID_MAIN, | ||
loc: { | ||
column: 0, | ||
file: ID_MAIN, | ||
line: 3 | ||
}, | ||
message: | ||
'Module "main.js" tried to import "external" with "type": "bar" assertions, but it was already imported elsewhere with "type": "foo" assertions. Please ensure that import assertions for the same module are always consistent.', | ||
pos: 63 | ||
}, | ||
{ | ||
code: 'INCONSISTENT_IMPORT_ASSERTIONS', | ||
frame: ` | ||
2: import 'external' assert { type: 'foo' }; | ||
3: import 'external' assert { type: 'bar' }; | ||
4: import 'external'; | ||
^ | ||
5: import('external', { assert: { type: 'baz' } }); | ||
6: import './dep.js' assert { type: 'foo' };`, | ||
id: ID_MAIN, | ||
loc: { | ||
column: 0, | ||
file: ID_MAIN, | ||
line: 4 | ||
}, | ||
message: | ||
'Module "main.js" tried to import "external" with no assertions, but it was already imported elsewhere with "type": "foo" assertions. Please ensure that import assertions for the same module are always consistent.', | ||
pos: 105 | ||
}, | ||
{ | ||
code: 'INCONSISTENT_IMPORT_ASSERTIONS', | ||
message: | ||
'Module "main.js" tried to import "external" with "type": "baz" assertions, but it was already imported elsewhere with "type": "foo" assertions. Please ensure that import assertions for the same module are always consistent.' | ||
}, | ||
{ | ||
code: 'INCONSISTENT_IMPORT_ASSERTIONS', | ||
message: | ||
'Module "other.js" tried to import "external" with "type": "quuz" assertions, but it was already imported elsewhere with "type": "foo" assertions. Please ensure that import assertions for the same module are always consistent.' | ||
}, | ||
{ | ||
code: 'INCONSISTENT_IMPORT_ASSERTIONS', | ||
message: | ||
'Module "other.js" tried to import "dep.js" with "type": "bar" assertions, but it was already imported elsewhere with "type": "foo" assertions. Please ensure that import assertions for the same module are always consistent.' | ||
} | ||
] | ||
}; |
Empty file.
6 changes: 6 additions & 0 deletions
6
test/function/samples/import-assertions/warn-assertion-conflicts/main.js
This file contains 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,6 @@ | ||
import './other.js'; | ||
import 'external' assert { type: 'foo' }; | ||
import 'external' assert { type: 'bar' }; | ||
import 'external'; | ||
import('external', { assert: { type: 'baz' } }); | ||
import './dep.js' assert { type: 'foo' }; |
2 changes: 2 additions & 0 deletions
2
test/function/samples/import-assertions/warn-assertion-conflicts/other.js
This file contains 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,2 @@ | ||
import 'external' assert { type: 'quuz' }; | ||
import './dep.js' assert { type: 'bar' }; |