Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion packages/code-analyzer-eslint-engine/package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "@salesforce/code-analyzer-eslint-engine",
"description": "Plugin package that adds 'eslint' as an engine into Salesforce Code Analyzer",
"version": "0.47.0",
"version": "0.48.0-SNAPSHOT",
"author": "The Salesforce Code Analyzer Team",
"license": "BSD-3-Clause",
"homepage": "https://developer.salesforce.com/docs/platform/salesforce-code-analyzer/overview",
Expand Down
9 changes: 8 additions & 1 deletion packages/code-analyzer-eslint-engine/src/base-config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,9 @@ import globals from "globals";
* disable_typescript_base_config), they disable the BASE RULES but NOT parsing capability.
* We always configure parsers to ensure files can be analyzed, even with minimal rule sets.
*/
// Aura components (ES5 with the $A API) are not LWC/modern JS, so the JS and LWC base configs must not apply to them
const AURA_FILE_PATTERNS: string[] = ['**/aura/**'];

export class BaseConfigFactory {
private readonly engineConfig: ESLintEngineConfig;

Expand Down Expand Up @@ -151,6 +154,7 @@ export class BaseConfigFactory {
const baseJsConfig: Linter.Config = {
...eslintJs.configs.all,
files: allJsFilePatterns,
ignores: AURA_FILE_PATTERNS,
languageOptions: {
...configs[0].languageOptions // Reuses Babel parser with @babel/preset-react
}
Expand All @@ -174,7 +178,8 @@ export class BaseConfigFactory {
// Then insert the base JS config at position 1
const lwcConfigs: Linter.Config[] = configs.map(config => ({
...config,
files: lwcFilePatterns
files: lwcFilePatterns,
ignores: AURA_FILE_PATTERNS
}));
lwcConfigs[1] = baseJsConfig;

Expand Down Expand Up @@ -234,6 +239,7 @@ export class BaseConfigFactory {
return [{
...base,
files: allJsFilePatterns,
ignores: AURA_FILE_PATTERNS,
languageOptions: {
parser: babelParser,
parserOptions: enhancedParserOptions
Expand All @@ -245,6 +251,7 @@ export class BaseConfigFactory {
return [{
...base,
files: allJsFilePatterns,
ignores: AURA_FILE_PATTERNS,
languageOptions: {
parserOptions: {
ecmaFeatures: {
Expand Down
13 changes: 13 additions & 0 deletions packages/code-analyzer-eslint-engine/test/engine.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1170,6 +1170,19 @@ describe('Tests for fixes and suggestions in runRules', () => {
expect(fix.fixedCode).toContain('const');
});

it('Files within aura folders are not linted with JS/LWC base configs while other files are', async () => {
const auraWorkspace: string = path.join(testDataFolder, 'workspaceWithAuraAndLwc');
const auraFile: string = path.join(auraWorkspace, 'aura', 'myCmp', 'myCmpController.js');
const lwcFile: string = path.join(auraWorkspace, 'lwc', 'myCmp', 'myCmp.js');
const engine: Engine = await createEngineFromPlugin(DEFAULT_CONFIG_FOR_TESTING);
const runOptions: RunOptions = createRunOptions(new Workspace('id', [auraWorkspace], [auraFile, lwcFile]));
const results: EngineRunResults = await engine.runRules(
['no-var', '@lwc/lwc-platform/no-aura', '@lwc/lwc/no-document-query'], runOptions);

expect(results.violations.filter(v => v.codeLocations[0].file === auraFile)).toHaveLength(0);
expect(results.violations.filter(v => v.codeLocations[0].file === lwcFile && v.ruleName === 'no-var').length).toBeGreaterThan(0);
});

it('Multiple violations in the same file produce fixes without errors', async () => {
const engine: Engine = await createEngineFromPlugin(DEFAULT_CONFIG_FOR_TESTING);
const runOptions: RunOptions = {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
({
doInit: function(component, event, helper) {
var x = 1;
var el = document.querySelector('div');
$A.log(x, el);
}
})
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
var y = 1;
console.log(y);
Loading