Skip to content

Commit 002ac9c

Browse files
authored
feat: Allow to use tryExtensions in the rule no-unpublished-import (#429)
1 parent 63cbdb9 commit 002ac9c

File tree

5 files changed

+36
-0
lines changed

5 files changed

+36
-0
lines changed

docs/rules/no-unpublished-import.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,11 @@ Please see the shared settings documentation for more information.
5151
This can be configured in the rule options or as a shared setting [`settings.convertPath`](../shared-settings.md#convertpath).
5252
Please see the shared settings documentation for more information.
5353

54+
#### tryExtensions
55+
56+
This can be configured in the rule options or as a shared setting [`settings.tryExtensions`](../shared-settings.md#tryextensions).
57+
Please see the shared settings documentation for more information.
58+
5459
### ignoreTypeImport
5560

5661
If using typescript, you may want to ignore type imports. This option allows you to do that.

lib/rules/no-unpublished-import.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ const getAllowModules = require("../util/get-allow-modules")
99
const getConvertPath = require("../util/get-convert-path")
1010
const getResolvePaths = require("../util/get-resolve-paths")
1111
const getResolverConfig = require("../util/get-resolver-config")
12+
const getTryExtensions = require("../util/get-try-extensions")
1213
const visitImport = require("../util/visit-import")
1314

1415
/**
@@ -18,6 +19,7 @@ const visitImport = require("../util/visit-import")
1819
* convertPath?: import('../util/get-convert-path').ConvertPath;
1920
* resolvePaths?: import('../util/get-resolve-paths').ResolvePaths;
2021
* resolverConfig?: import('../util/get-resolver-config').ResolverConfig;
22+
* tryExtensions?: import('../util/get-try-extensions').TryExtensions;
2123
* ignoreTypeImport?: boolean;
2224
* ignorePrivate?: boolean;
2325
* }?
@@ -42,6 +44,7 @@ module.exports = {
4244
convertPath: getConvertPath.schema,
4345
resolvePaths: getResolvePaths.schema,
4446
resolverConfig: getResolverConfig.schema,
47+
tryExtensions: getTryExtensions.schema,
4548
ignoreTypeImport: { type: "boolean", default: false },
4649
ignorePrivate: { type: "boolean", default: true },
4750
},

tests/fixtures/no-unpublished/4/abc.jsx

Whitespace-only changes.
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
{
2+
"name": "test",
3+
"version": "0.0.0",
4+
"files": [
5+
"index.jsx",
6+
"abc.jsx"
7+
]
8+
}

tests/lib/rules/no-unpublished-import.js

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -140,6 +140,16 @@ ruleTester.run("no-unpublished-import", rule, {
140140
code: "import a from 'virtual:package-scope/name';",
141141
options: [{ allowModules: ["virtual:package-scope"] }],
142142
},
143+
// try extensions
144+
{
145+
filename: fixture("4/index.jsx"),
146+
code: "import abc from './abc';",
147+
options: [
148+
{
149+
tryExtensions: [".jsx"],
150+
},
151+
],
152+
},
143153

144154
// Auto-published files only apply to root package directory
145155
{
@@ -280,6 +290,16 @@ ruleTester.run("no-unpublished-import", rule, {
280290
],
281291
errors: ['"../test.jsx" is not published.'],
282292
},
293+
// try extensions
294+
{
295+
filename: fixture("4/index.jsx"),
296+
code: "import abc from './abc';",
297+
errors: ['"./abc" is not published.'],
298+
// Without setting tryExtensions, it defaults to [".js", ".json", ".node"], and thus
299+
// cannot find the abc.jsx file, which is published.
300+
//
301+
// options: [{ tryExtensions: [".jsx"], }],
302+
},
283303

284304
// outside of the package.
285305
{

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy