diff --git a/language/linter.ts b/language/linter.ts index 62551f39..379e689c 100644 --- a/language/linter.ts +++ b/language/linter.ts @@ -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\`).`, @@ -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); diff --git a/language/models/cache.ts b/language/models/cache.ts index c24c6f82..dae0cb25 100644 --- a/language/models/cache.ts +++ b/language/models/cache.ts @@ -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) { diff --git a/tests/suite/basics.test.ts b/tests/suite/basics.test.ts index 6645932a..7badc2bd 100644 --- a/tests/suite/basics.test.ts +++ b/tests/suite/basics.test.ts @@ -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`); }); @@ -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`); diff --git a/tests/suite/linter.test.ts b/tests/suite/linter.test.ts index 72b08d7f..db1fa6f0 100644 --- a/tests/suite/linter.test.ts +++ b/tests/suite/linter.test.ts @@ -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 = [ @@ -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({ @@ -3403,4 +3403,25 @@ test('constant replace picking up wrong variable #330', async () => { type: 'StringLiteralDupe', newValue: undefined }); -}) \ No newline at end of file +}); + +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' + }); +}); \ No newline at end of file