Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add lowercase directives followup #298

Merged
merged 4 commits into from
Mar 20, 2024
Merged
Show file tree
Hide file tree
Changes from 2 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
3 changes: 1 addition & 2 deletions extension/server/src/providers/linter/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 = {
Expand Down
23 changes: 6 additions & 17 deletions language/linter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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.`,
Expand Down Expand Up @@ -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();
}
Expand All @@ -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()
});
}
Expand Down
3 changes: 1 addition & 2 deletions language/parserTypes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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}[];
Expand Down
4 changes: 2 additions & 2 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

45 changes: 6 additions & 39 deletions tests/suite/directives.js
Original file line number Diff line number Diff line change
Expand Up @@ -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`
});
},
Expand All @@ -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`
});
}
Expand Down