Skip to content

Commit cb3bc01

Browse files
fix: revert changes for html lint
1 parent 8596abb commit cb3bc01

File tree

4 files changed

+15
-38
lines changed

4 files changed

+15
-38
lines changed

lib/lwc-bundle.js

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -123,18 +123,18 @@ class LwcBundle {
123123
}
124124

125125
/**
126-
* Gets a unique key for this bundle based on its js file since komaci only supports js files. This key is used as file name for further linting.
126+
* Gets a unique key for this bundle based on its primary file
127127
*
128-
* @returns {string} A unique key in the format `<base file name>_<uuid>.js`
128+
* @returns {string} A unique key in the format `<base file name>_<uuid>.<extension>`
129129
*/
130130
getBundleKey() {
131131
const primaryFile = this.primaryFile;
132132
if (!primaryFile) {
133133
throw new Error('Cannot generate bundle key: no primary file exists');
134134
}
135135

136-
const { name } = parse(primaryFile.filename);
137-
return `${name}_${this.#primaryFileUuidKey}.js`;
136+
const { name, ext } = parse(primaryFile.filename);
137+
return `${name}_${this.#primaryFileUuidKey}${ext}`;
138138
}
139139

140140
/**

lib/processor.js

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -124,15 +124,18 @@ class BundleAnalyzer {
124124

125125
setLwcBundleCacheEntry(this.#lwcBundle);
126126

127-
// Get the unique key for this bundle, which will be used as the filename for ESLint processing. It should always be a js file since komaci only supports js files.
127+
// Get the unique key for this bundle, which will be used as the filename for ESLint processing
128128
const uniqueFilename = this.#lwcBundle.getBundleKey();
129129

130-
// For JavaScript files, we need to return the JS content from the bundle so that ESLint can parse it
131-
// and properly handle disable comments. For HTML files, we return
132-
// the JS content too so that rules can run and report violations targeting
133-
// the HTML file.
134-
135-
return [{ text: this.#lwcBundle.js?.content || '', filename: uniqueFilename }];
130+
// For JavaScript files, we need to return the original text so that ESLint can parse it
131+
// and properly handle disable comments. For all other file types (like HTML), we return
132+
// an empty string to prevent ESLint from attempting to parse them, since our rules
133+
// don't need the parsed AST for non-JS files.
134+
if (fileExtension === '.js') {
135+
return [{ text, filename: uniqueFilename }];
136+
} else {
137+
return [{ text: '', filename: uniqueFilename }];
138+
}
136139
};
137140

138141
/**

test/lib/lwc-bundle.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -192,7 +192,7 @@ describe('LwcBundle', () => {
192192
});
193193

194194
it('should throw error when no primary file exists', () => {
195-
const bundle = LwcBundle.lwcBundleFromContent('test', undefined, 'html content');
195+
const bundle = LwcBundle.lwcBundleFromContent('test', 'js content', 'html content');
196196
expect(() => bundle.getBundleKey()).to.throw(
197197
'Cannot generate bundle key: no primary file exists'
198198
);

test/lib/rules/programmatic-bundle-lint.js

Lines changed: 0 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -86,11 +86,6 @@ export default class TestComponent extends LightningElement {
8686
htmlContent // HTML content
8787
);
8888

89-
// 5. Lint HTML file
90-
const htmlErrors = linter.verify(htmlContent, config, {
91-
filename: 'testComponent.html'
92-
});
93-
9489
// Verify we got violations for the JS file
9590
// The displayValue getter violates the rule because it's referenced in HTML
9691
expect(jsErrors.length).toBeGreaterThan(0);
@@ -105,17 +100,6 @@ export default class TestComponent extends LightningElement {
105100
);
106101
expect(jsViolation.message).toBe('Getters can only contain a return statement.');
107102
expect(jsViolation.line).toBeGreaterThan(0);
108-
109-
expect(htmlErrors.length).toBe(1);
110-
const htmlViolation = htmlErrors[0];
111-
expect(htmlViolation).toBeDefined();
112-
expect(htmlViolation.ruleId).toBe(
113-
'@salesforce/lwc-graph-analyzer/no-composition-on-unanalyzable-property-non-public'
114-
);
115-
expect(htmlViolation.message).toBe(
116-
"This child component references an unanalyzable property 'descriptionValue' that’s not a public property."
117-
);
118-
expect(htmlViolation.line).toBeGreaterThan(0);
119103
});
120104

121105
it('should return empty violations when no errors exist', () => {
@@ -144,23 +128,13 @@ export default class MyComponent extends LightningElement {
144128
filename: 'myComponent.js'
145129
});
146130

147-
const htmlErrors = linter.verify(htmlContent, config, {
148-
filename: 'myComponent.html'
149-
});
150-
151131
// No violations expected since we're using a simple property, not a getter
152132
const jsViolations = jsErrors.filter(
153133
(err) =>
154134
err.ruleId ===
155135
'@salesforce/lwc-graph-analyzer/no-getter-contains-more-than-return-statement'
156136
);
157-
const htmlViolations = htmlErrors.filter(
158-
(err) =>
159-
err.ruleId ===
160-
'@salesforce/lwc-graph-analyzer/no-getter-contains-more-than-return-statement'
161-
);
162137

163138
expect(jsViolations.length).toBe(0);
164-
expect(htmlViolations.length).toBe(0);
165139
});
166140
});

0 commit comments

Comments
 (0)