Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: Call namespace error as a warning (#3475)
* feat: call namespace as a warning * Fix prettier config * Add tagged template literals to test to improve coverage Co-authored-by: Lukas Taegert-Atkinson <lukas.taegert-atkinson@tngtech.com>
- Loading branch information
1 parent
5eb01fb
commit c69c41b
Showing
7 changed files
with
48 additions
and
49 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,7 @@ | ||
{ | ||
"arrowParens": "avoid", | ||
"printWidth": 100, | ||
"singleQuote": true, | ||
"useTabs": true, | ||
"printWidth": 100 | ||
"trailingComma": "none", | ||
"useTabs": true | ||
} |
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
27 changes: 10 additions & 17 deletions
27
test/function/samples/cannot-call-external-namespace/_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 |
---|---|---|
@@ -1,21 +1,14 @@ | ||
const path = require('path'); | ||
const assert = require('assert'); | ||
|
||
module.exports = { | ||
description: 'errors if code calls an external namespace', | ||
error: { | ||
code: 'CANNOT_CALL_NAMESPACE', | ||
message: `Cannot call a namespace ('foo')`, | ||
pos: 28, | ||
watchFiles: [path.resolve(__dirname, 'main.js')], | ||
loc: { | ||
file: path.resolve(__dirname, 'main.js'), | ||
line: 2, | ||
column: 0 | ||
}, | ||
frame: ` | ||
1: import * as foo from 'foo'; | ||
2: foo(); | ||
^ | ||
` | ||
description: 'warns if code calls an external namespace', | ||
options: { | ||
external: ['fs'] | ||
}, | ||
warnings(warnings) { | ||
assert.deepStrictEqual(warnings.map(String), [ | ||
"main.js (4:1) Cannot call a namespace ('foo')", | ||
"main.js (8:1) Cannot call a namespace ('foo')" | ||
]); | ||
} | ||
}; |
11 changes: 9 additions & 2 deletions
11
test/function/samples/cannot-call-external-namespace/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 |
---|---|---|
@@ -1,2 +1,9 @@ | ||
import * as foo from 'foo'; | ||
foo(); | ||
import * as foo from 'fs'; | ||
|
||
try { | ||
foo(); | ||
} catch (e) {} | ||
|
||
try { | ||
foo``; | ||
} catch (e) {} |
24 changes: 7 additions & 17 deletions
24
test/function/samples/cannot-call-internal-namespace/_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 |
---|---|---|
@@ -1,21 +1,11 @@ | ||
const path = require('path'); | ||
const assert = require('assert'); | ||
|
||
module.exports = { | ||
description: 'errors if code calls an internal namespace', | ||
error: { | ||
code: 'CANNOT_CALL_NAMESPACE', | ||
message: `Cannot call a namespace ('foo')`, | ||
pos: 33, | ||
watchFiles: [path.resolve(__dirname, 'main.js'), path.resolve(__dirname, 'foo.js')], | ||
loc: { | ||
file: path.resolve(__dirname, 'main.js'), | ||
line: 2, | ||
column: 0 | ||
}, | ||
frame: ` | ||
1: import * as foo from './foo.js'; | ||
2: foo(); | ||
^ | ||
` | ||
description: 'warns if code calls an internal namespace', | ||
warnings(warnings) { | ||
assert.deepStrictEqual(warnings.map(String), [ | ||
"main.js (4:1) Cannot call a namespace ('foo')", | ||
"main.js (8:1) Cannot call a namespace ('foo')" | ||
]); | ||
} | ||
}; |
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 |
---|---|---|
@@ -1,2 +1,9 @@ | ||
import * as foo from './foo.js'; | ||
foo(); | ||
|
||
try { | ||
foo(); | ||
} catch {} | ||
|
||
try { | ||
foo``; | ||
} catch {} |