Skip to content

Commit c87f757

Browse files
committed
feat: update error messages for cross feature imports and clarify optional features directory in tests
1 parent e942e29 commit c87f757

File tree

4 files changed

+8
-8
lines changed

4 files changed

+8
-8
lines changed

docs/rules/no-cross-feature-imports.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,7 @@ Notes:
7474

7575
## Project Structure
7676

77-
```text
77+
```
7878
src/
7979
├── features/
8080
│ ├── user/

src/rules/enforce-feature-exports.js

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,6 @@ export default {
4545
],
4646
defaultOptions: [defaultOptions],
4747
messages: {
48-
missingFeaturesDir: 'Project is missing `{{src}}/{{featuresDir}}` directory. Create features under `{{src}}/{{featuresDir}}`',
4948
missingIndex: 'Feature `{{feature}}` is missing a public API file (expected one of: {{indexFiles}})',
5049
},
5150
},
@@ -76,7 +75,7 @@ export default {
7675
try {
7776
const entries = fs.readdirSync(srcDir)
7877
if (!entries.includes(featuresDirName)) {
79-
context.report({ loc: { line: 1, column: 0 }, messageId: 'missingFeaturesDir', data: { src, featuresDir: featuresDirName } })
78+
// features directory is optional; do not report an error when absent
8079
return
8180
}
8281

src/rules/no-cross-feature-imports.js

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,8 @@ export default {
3333
},
3434
],
3535
messages: {
36-
crossFeatureImport: 'Cannot import "{{importPath}}" from outside "{{name}}". Only imports from "{{allowedPath}}" are allowed.',
36+
crossFeatureImport:
37+
'Cannot import "{{importPath}}" from outside feature "{{featureName}}". Only imports from "{{allowedPath}}" are allowed.',
3738
},
3839
},
3940
create(context) {
@@ -57,7 +58,7 @@ export default {
5758
context.report({
5859
node: node.source,
5960
messageId: 'crossFeatureImport',
60-
data: { importPath: source, name: modulePublicName, allowedPath: `@/${modulesDir}/${modulePublicName}` },
61+
data: { importPath: source, featureName: modulePublicName, allowedPath: `@/${modulesDir}/${modulePublicName}` },
6162
})
6263
return
6364
}
@@ -70,7 +71,7 @@ export default {
7071
context.report({
7172
node: node.source,
7273
messageId: 'crossFeatureImport',
73-
data: { importPath: source, name: featureInfo.featureName, allowedPath: featureInfo.allowedPath },
74+
data: { importPath: source, featureName: featureInfo.featureName, allowedPath: featureInfo.allowedPath },
7475
})
7576
}
7677
},

tests/enforce-feature-exports.spec.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,14 +17,14 @@ describe('enforce-feature-exports rule', () => {
1717
settings: {},
1818
})
1919

20-
it('reports when features directory is missing', () => {
20+
it('does not report when features directory is missing (features optional)', () => {
2121
vi.spyOn(fs, 'readdirSync').mockReturnValue(['components', 'main.ts'])
2222

2323
const context = createContext()
2424
const rule = featureStructureRule.create(context)
2525
if (rule.Program) rule.Program()
2626

27-
expect(context.report).toHaveBeenCalledWith(expect.objectContaining({ messageId: 'missingFeaturesDir' }))
27+
expect(context.report).not.toHaveBeenCalled()
2828
})
2929

3030
it('reports features missing index files', () => {

0 commit comments

Comments
 (0)