From 83db7bc5cf9fca6e76f95fcf1321e77ed9610d0a Mon Sep 17 00:00:00 2001 From: Liam Barry Allan Date: Fri, 28 Oct 2022 16:23:15 -0400 Subject: [PATCH] Fix for invalid keyword check on prototypes Signed-off-by: Liam Barry Allan --- schemas/rpglint.json | 2 +- server/src/language/linter.js | 4 ++-- tests/suite/linter.js | 24 ++++++++++++++++++++---- 3 files changed, 23 insertions(+), 7 deletions(-) diff --git a/schemas/rpglint.json b/schemas/rpglint.json index 89f96325..757e5d44 100644 --- a/schemas/rpglint.json +++ b/schemas/rpglint.json @@ -23,7 +23,7 @@ "PrototypeCheck": { "$id": "#/properties/PrototypeCheck", "type": "boolean", - "description": "Prototypes can only be defined with either EXT, EXTPGM or EXTPROC" + "description": "Prototypes can only be defined with either EXTPGM or EXTPROC." }, "ForceOptionalParens": { "$id": "#/properties/ForceOptionalParens", diff --git a/server/src/language/linter.js b/server/src/language/linter.js index e5f6e947..218c15fd 100644 --- a/server/src/language/linter.js +++ b/server/src/language/linter.js @@ -8,7 +8,7 @@ import { Range, Position } from "./models/DataPoints"; const errorText = { 'BlankStructNamesCheck': `Struct names cannot be blank (\`*N\`).`, 'QualifiedCheck': `Struct names must be qualified (\`QUALIFIED\`).`, - 'PrototypeCheck': `Prototypes can only be defined with either \`EXT\`, \`EXTPGM\` or \`EXTPROC\``, + 'PrototypeCheck': `Prototypes can only be defined with either \`EXTPGM\` or \`EXTPROC\``, 'ForceOptionalParens': `Expressions must be surrounded by brackets.`, 'NoOCCURS': `\`OCCURS\` is not allowed.`, 'NoSELECTAll': `\`SELECT *\` is not allowed in Embedded SQL.`, @@ -471,7 +471,7 @@ export default class Linter { inPrototype = true; if (rules.PrototypeCheck || rules.NoExtProgramVariable) { - const extIndex = statement.findIndex(part => part.value && part.value.toUpperCase().startsWith(`EXT`)); + const extIndex = statement.findIndex(part => part.value && [`EXTPGM`, `EXTPROC`].includes(part.value.toUpperCase())); if (extIndex >= 0) { if (rules.NoExtProgramVariable) { diff --git a/tests/suite/linter.js b/tests/suite/linter.js index fa0dec19..f08bf90a 100644 --- a/tests/suite/linter.js +++ b/tests/suite/linter.js @@ -1783,10 +1783,6 @@ exports.linter21 = async () => { }); } -/** - * Test procedure length. - * When Procedure is defined, the prototype is overridden. - */ exports.linter22 = async () => { const lines = [ `**FREE`, @@ -1821,6 +1817,26 @@ exports.linter22 = async () => { }); } +exports.linter22_b = async () => { + const lines = [ + `**FREE`, + ``, + `Dcl-Pr TheProcedure EXTPROC;`, + ` parmA CHAR(20);`, + `End-Pr`, + ``, + `Dcl-S theVar CHAR(20);`, + ].join(`\n`); + + const parser = parserSetup(); + const cache = await parser.getDocs(uri, lines); + const { errors } = Linter.getErrors({uri, content: lines}, { + PrototypeCheck: true + }, cache); + + assert.strictEqual(errors.length, 0); +} + exports.linter23 = async () => { const lines = [ `**free`,