Skip to content

Commit

Permalink
Fix issues where blank comments were errors
Browse files Browse the repository at this point in the history
Signed-off-by: Liam Barry Allan <[email protected]>
  • Loading branch information
worksofliam committed Jan 31, 2023
1 parent f71c04f commit d1b4bbc
Show file tree
Hide file tree
Showing 2 changed files with 48 additions and 53 deletions.
35 changes: 12 additions & 23 deletions server/src/language/linter.js
Original file line number Diff line number Diff line change
Expand Up @@ -168,30 +168,19 @@ export default class Linter {
if (isLineComment) {
const comment = line.substring(currentIndent + 2).trimEnd();
if (rules.PrettyComments) {
if (comment === ``) {
errors.push({
range: new Range(
new Position(lineNumber, currentIndent),
new Position(lineNumber, currentIndent + 2)
),
type: `PrettyComments`,
newValue: ``
});
} else {
// We check for the slash because the documentation requires ///.
if (comment !== `/`) {
const startSpaces = comment.search(/\S/);
// We check for the slash because the documentation requires ///.
if (comment !== `/`) {
const startSpaces = comment.search(/\S/);

if (startSpaces === 0) {
errors.push({
range: new Range(
new Position(lineNumber, currentIndent),
new Position(lineNumber, currentIndent + 2)
),
type: `PrettyComments`,
newValue: `// `,
});
}
if (startSpaces === 0) {
errors.push({
range: new Range(
new Position(lineNumber, currentIndent),
new Position(lineNumber, currentIndent + 2)
),
type: `PrettyComments`,
newValue: `// `,
});
}
}
} else {
Expand Down
66 changes: 36 additions & 30 deletions tests/suite/linter.js
Original file line number Diff line number Diff line change
Expand Up @@ -1358,18 +1358,9 @@ exports.linter15 = async () => {
PrettyComments: true
}, cache);

assert.strictEqual(errors.length, 5, `Expect length of 5`);
assert.strictEqual(errors.length, 2, `Expect length of 5`);

assert.deepStrictEqual(errors[0], {
type: `PrettyComments`,
newValue: ``,
range: new Range(
new Position(4, 0),
new Position(4, 2),
),
});

assert.deepStrictEqual(errors[1], {
type: `PrettyComments`,
newValue: `// `,
range: new Range(
Expand All @@ -1378,32 +1369,14 @@ exports.linter15 = async () => {
),
});

assert.deepStrictEqual(errors[2], {
type: `PrettyComments`,
newValue: ``,
range: new Range(
new Position(6, 0),
new Position(6, 2),
),
});

assert.deepStrictEqual(errors[3], {
assert.deepStrictEqual(errors[1], {
type: `PrettyComments`,
newValue: `// `,
range: new Range(
new Position(14, 2),
new Position(14, 4),
),
});

assert.deepStrictEqual(errors[4], {
type: `PrettyComments`,
newValue: ``,
range: new Range(
new Position(16, 2),
new Position(16, 4),
),
});
};

/**
Expand Down Expand Up @@ -3370,4 +3343,37 @@ exports.dcl_parm_issue184 = async () => {
assert.strictEqual(parms[0].name, `select`);
assert.strictEqual(parms[1].name, `name`);
assert.strictEqual(parms[2].name, `address`);
}
}

exports.prettyCommentsChange = async () => {
const lines = [
`**FREE`,
``,
`Ctl-Opt DFTACTGRP(*No);`,
``,
`Dcl-s MyVariable2 Char(20);`,
``,
`// my constant`,
`//`,
`// second line`,
`Dcl-C theConstant 'Hello world';`,
`//comment with bad indent`,
].join(`\n`);

const parser = parserSetup();
const cache = await parser.getDocs(uri, lines);
const { errors } = Linter.getErrors({ uri, content: lines }, {
PrettyComments: true
}, cache);

assert.strictEqual(errors.length, 1);

assert.deepStrictEqual(errors[0], {
type: `PrettyComments`,
newValue: `// `,
range: new Range(
new Position(10, 0),
new Position(10, 2),
),
});
};

0 comments on commit d1b4bbc

Please sign in to comment.