From 745c321d94e4d67a8d98ef7df1ed4f7f1dabbdf1 Mon Sep 17 00:00:00 2001 From: Richard Moulton Date: Sun, 4 Feb 2024 15:46:59 +0000 Subject: [PATCH] Remove UppercaseDirectives and fix DirectiveCase --- .../server/src/providers/linter/index.ts | 3 +- language/linter.ts | 23 +++------- language/parserTypes.ts | 3 +- package-lock.json | 4 +- tests/suite/directives.js | 45 +++---------------- 5 files changed, 16 insertions(+), 62 deletions(-) diff --git a/extension/server/src/providers/linter/index.ts b/extension/server/src/providers/linter/index.ts index 415d7547..288a47b6 100644 --- a/extension/server/src/providers/linter/index.ts +++ b/extension/server/src/providers/linter/index.ts @@ -314,8 +314,7 @@ export function getActions(document: TextDocument, errors: IssueRange[]) { case `SpecificCasing`: case `IncorrectVariableCase`: - case `DirectiveCasing`: - case `UppercaseDirectives`: + case `DirectiveCase`: if (error.newValue) { action = CodeAction.create(`Correct casing to '${error.newValue}'`, CodeActionKind.QuickFix); action.edit = { diff --git a/language/linter.ts b/language/linter.ts index 306a0b08..fff0b851 100644 --- a/language/linter.ts +++ b/language/linter.ts @@ -26,8 +26,7 @@ const errorText = { 'StringLiteralDupe': `Same string literal used more than once. Consider using a constant instead.`, 'RequireBlankSpecial': `\`*BLANK\` should be used over empty string literals.`, 'CopybookDirective': `Directive does not match requirement.`, - 'DirectiveCasing': `Does not match required case.`, - 'UppercaseDirectives': `Directives must be in uppercase. UppercaseDirectives option is deprecated, consider using DirectiveCasing.`, + 'DirectiveCase': `Does not match required case.`, 'NoSQLJoins': `SQL joins are not allowed. Consider creating a view instead.`, 'NoGlobalsInProcedures': `Global variables should not be referenced in procedures.`, 'NoCTDATA': `\`CTDATA\` is not allowed.`, @@ -285,7 +284,7 @@ export default class Linter { if (rules.CopybookDirective) { let correctDirective = `/${rules.CopybookDirective.toUpperCase()}`; let correctValue = value.toUpperCase(); - if (rules.DirectiveCasing === `lower`) { + if (rules.DirectiveCase === `lower`) { correctDirective = correctDirective.toLowerCase(); correctValue = value.toLowerCase(); } @@ -300,31 +299,21 @@ export default class Linter { } } - if (rules.DirectiveCasing === `lower`) { + if (rules.DirectiveCase === `lower`) { if (value !== value.toLowerCase()) { errors.push({ offset: { position: statement[0].range.start, end: statement[0].range.end }, - type: `DirectiveCasing`, + type: `DirectiveCase`, newValue: value.toLowerCase() }); } } - if (rules.DirectiveCasing === `upper`) { + if (rules.DirectiveCase === `upper`) { if (value !== value.toUpperCase()) { errors.push({ offset: { position: statement[0].range.start, end: statement[0].range.end }, - type: `DirectiveCasing`, - newValue: value.toUpperCase() - }); - } - } - - if (rules.UppercaseDirectives) { - if (value !== value.toUpperCase()) { - errors.push({ - offset: { position: statement[0].range.start, end: statement[0].range.end }, - type: `UppercaseDirectives`, + type: `DirectiveCase`, newValue: value.toUpperCase() }); } diff --git a/language/parserTypes.ts b/language/parserTypes.ts index 29a69d03..085404d0 100644 --- a/language/parserTypes.ts +++ b/language/parserTypes.ts @@ -41,8 +41,7 @@ export interface Rules { literalMinimum?: number; RequireBlankSpecial?: boolean; CopybookDirective?: "copy"|"include"; - DirectiveCasing?: "lower"|"upper"; - UppercaseDirectives?: boolean; + DirectiveCase?: "lower"|"upper"; NoSQLJoins?: boolean; NoGlobalsInProcedures?: boolean; SpecificCasing?: {operation: string, expected: string}[]; diff --git a/package-lock.json b/package-lock.json index 80b622b0..1c88cf07 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,12 +1,12 @@ { "name": "vscode-rpgle", - "version": "0.24.0", + "version": "0.26.0", "lockfileVersion": 2, "requires": true, "packages": { "": { "name": "vscode-rpgle", - "version": "0.24.0", + "version": "0.26.0", "hasInstallScript": true, "license": "MIT", "devDependencies": { diff --git a/tests/suite/directives.js b/tests/suite/directives.js index 6ece64e3..4667e22e 100644 --- a/tests/suite/directives.js +++ b/tests/suite/directives.js @@ -520,53 +520,20 @@ module.exports = { const cache = await parser.getDocs(uri, lines, {withIncludes: true, ignoreCache: true}); const { errors } = Linter.getErrors({ uri, content: lines }, { - DirectiveCasing: `upper` + DirectiveCase: `upper` }, cache); assert.strictEqual(errors.length, 2, `Expect length of 2`); assert.deepStrictEqual(errors[0], { offset: { position: 31, end: 36 }, - type: `DirectiveCasing`, + type: `DirectiveCase`, newValue: `/COPY` }); assert.deepStrictEqual(errors[1], { offset: { position: 65, end: 70 }, - type: `DirectiveCasing`, - newValue: `/COPY` - }); - }, - - uppercase2: async () => { - const lines = [ - `**FREE`, - `Ctl-Opt DftActGrp(*No);`, - `/copy './tests/rpgle/copy1.rpgle'`, - `/Copy './tests/rpgle/copy2.rpgle'`, - `/COPY './tests/rpgle/copy3.rpgle'`, - `Dcl-S MyCustomerName1 like(CustomerName_t);`, - `MyCustomerName1 = 'John Smith';`, - `dsply MyCustomerName1;`, - `Return;` - ].join(`\n`); - - const cache = await parser.getDocs(uri, lines, {withIncludes: true, ignoreCache: true}); - const { errors } = Linter.getErrors({ uri, content: lines }, { - UppercaseDirectives: true - }, cache); - - assert.strictEqual(errors.length, 2, `Expect length of 2`); - - assert.deepStrictEqual(errors[0], { - offset: { position: 31, end: 36 }, - type: `UppercaseDirectives`, - newValue: `/COPY` - }); - - assert.deepStrictEqual(errors[1], { - offset: { position: 65, end: 70 }, - type: `UppercaseDirectives`, + type: `DirectiveCase`, newValue: `/COPY` }); }, @@ -586,20 +553,20 @@ module.exports = { const cache = await parser.getDocs(uri, lines, {withIncludes: true, ignoreCache: true}); const { errors } = Linter.getErrors({ uri, content: lines }, { - DirectiveCasing: `lower` + DirectiveCase: `lower` }, cache); assert.strictEqual(errors.length, 2, `Expect length of 2`); assert.deepStrictEqual(errors[0], { offset: { position: 65, end: 70 }, - type: `DirectiveCasing`, + type: `DirectiveCase`, newValue: `/copy` }); assert.deepStrictEqual(errors[1], { offset: { position: 99, end: 104 }, - type: `DirectiveCasing`, + type: `DirectiveCase`, newValue: `/copy` }); }