Skip to content

Commit

Permalink
Merge pull request #340 from codefori/fix/remove_some_rules_for_includes
Browse files Browse the repository at this point in the history
Fix linter behavior for RPGLEINC files
  • Loading branch information
worksofliam authored Nov 10, 2024
2 parents e97f442 + cd82165 commit 0ed394f
Show file tree
Hide file tree
Showing 4 changed files with 34 additions and 5 deletions.
11 changes: 11 additions & 0 deletions language/linter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,9 @@ import Document from "./document";
import { IssueRange, Offset, Rules, SelectBlock } from "./parserTypes";
import Declaration from "./models/declaration";

const BANNED_FROM_INCLUDES = [`NoUnreferenced`];
const INCLUDE_EXTENSIONS = [`rpgleinc`, `rpgleh`];

const errorText = {
'BlankStructNamesCheck': `Struct names cannot be blank (\`*N\`).`,
'QualifiedCheck': `Struct names must be qualified (\`QUALIFIED\`).`,
Expand Down Expand Up @@ -60,6 +63,14 @@ export default class Linter {
const indentEnabled = rules.indent !== undefined;
const indent = rules.indent || 2;

const uriExtension = data.uri.split('.').pop().toLowerCase();

if (INCLUDE_EXTENSIONS.includes(uriExtension)) {
for (const banned of BANNED_FROM_INCLUDES) {
rules[banned] = false;
}
}

// Excluding indent
const ruleCount = Object.keys(rules).length - (rules.indent ? 1 : 0);

Expand Down
1 change: 0 additions & 1 deletion language/models/cache.ts
Original file line number Diff line number Diff line change
Expand Up @@ -191,7 +191,6 @@ export default class Cache {
const currentProcedure = this.procedures.find(proc => lineNumber >= proc.range.start && lineNumber <= proc.range.end);

if (currentProcedure && currentProcedure.scope) {
console.log(currentProcedure.scope.constants);
const localDef = currentProcedure.scope.constants.find(def => def.keyword[upperValue] === true);

if (localDef) {
Expand Down
2 changes: 0 additions & 2 deletions tests/suite/basics.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1162,7 +1162,6 @@ test(`exec_14`, async () => {

const cache = await parser.getDocs(uri, lines, {withIncludes: true, ignoreCache: true});

console.log(cache.sqlReferences);
expect(cache.sqlReferences.length).toBe(1);
expect(cache.sqlReferences[0].name).toBe(`table1`);
});
Expand Down Expand Up @@ -1233,7 +1232,6 @@ test('keywords over multiple lines', async () => {
expect(invoiceParm.keyword[`CONST`]).toBe(true);

const detailParm = invoice_get_invoice.subItems[2];
console.log(detailParm);
expect(detailParm.name).toBe(`details`);
expect(detailParm.keyword[`LIKEDS`]).toBe(`INVOICE_GET_INVOICE_SALES_DETAIL_DS`);
expect(detailParm.keyword[`DIM`]).toBe(`INVOICE_MAX_DETAILS`);
Expand Down
25 changes: 23 additions & 2 deletions tests/suite/linter.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import { test, expect } from "vitest";

const parser = setupParser();
const uri = `source.rpgle`;
const includeUri = `source.rpgleinc`;

test("linter_indent_multi_1", async () => {
const lines = [
Expand Down Expand Up @@ -3389,7 +3390,6 @@ test('constant replace picking up wrong variable #330', async () => {
StringLiteralDupe: true
}, cache);

console.log(errors);
expect(errors.length).toBe(2);

expect(errors[0]).toMatchObject({
Expand All @@ -3403,4 +3403,25 @@ test('constant replace picking up wrong variable #330', async () => {
type: 'StringLiteralDupe',
newValue: undefined
});
})
});

test('Linter running on rpgleinc', async () => {
const lines = [
`**free`,
`Dcl-S CustomerName_t varchar(40) template;`,
].join(`\n`);

const cache = await parser.getDocs(includeUri, lines, { ignoreCache: true, withIncludes: true });
const { errors } = Linter.getErrors({ uri: includeUri, content: lines }, {
IncorrectVariableCase: true,
NoUnreferenced: true,
SpecificCasing: [{operation: "dcl-s", expected: `DCL-S`}]
}, cache);

expect(errors.length).toBe(1);
expect(errors[0]).toMatchObject({
offset: { position: 7, end: 12 },
type: 'SpecificCasing',
newValue: 'DCL-S'
});
});

0 comments on commit 0ed394f

Please sign in to comment.