Skip to content

Commit

Permalink
Fix for linter skip special comment
Browse files Browse the repository at this point in the history
  • Loading branch information
worksofliam committed Feb 15, 2022
1 parent 6e744cf commit 63ed189
Show file tree
Hide file tree
Showing 3 changed files with 60 additions and 5 deletions.
10 changes: 6 additions & 4 deletions src/language/linter.js
Original file line number Diff line number Diff line change
Expand Up @@ -125,14 +125,13 @@ module.exports = class Linter {
/** @type {{value: string, definition?: string, list: {range: vscode.Range, offset: {position: number, length: number}}[]}[]} */
const stringLiterals = [];

for (const currentLine of lines) {
for (lineNumber = 0; lineNumber < lines.length; lineNumber++) {
const currentLine = lines[lineNumber];
currentIndent = currentLine.search(/\S/);
let line = currentLine.trimEnd();

let upperLine = line.trim().toUpperCase();

lineNumber += 1;

isLineComment = line.trimStart().startsWith(`//`);

if (currentIndent >= 0) {
Expand Down Expand Up @@ -191,7 +190,8 @@ module.exports = class Linter {

// Special comment check
if (comment.trim() === `@rpglint-skip`) {
break;
lineNumber += 1;
continue;
}
}

Expand Down Expand Up @@ -246,6 +246,8 @@ module.exports = class Linter {
let value;

if (statement.length >= 1) {
if (statement[0].type === `directive` && statement[0].value.toUpperCase() === `/EOF`) break;

switch (statement[0].type) {
case `format`:
if (statement[0].value.toUpperCase() === `**CTDATA`) {
Expand Down
5 changes: 5 additions & 0 deletions src/language/parser.js
Original file line number Diff line number Diff line change
Expand Up @@ -322,6 +322,11 @@ module.exports = class Parser {
parts = pieces[0].toUpperCase().split(` `).filter(piece => piece !== ``);
partsLower = pieces[0].split(` `).filter(piece => piece !== ``);

if (parts[0] === `/EOF`) {
// End of parsing for this file
break;
}

switch (parts[0]) {
case `DCL-F`:
const recordFormats = await this.fetchTable(parts[1]);
Expand Down
50 changes: 49 additions & 1 deletion tests/suite/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -1476,6 +1476,28 @@ module.exports = {
}, cache);

assert.strictEqual(indentErrors.length, 0, `Expect no indent errors`);
},

skip3: async () => {
const lines = [
`**free`,
`dcl-s xxField1 char(1);`,
``,
`// @rpglint-skip`,
`/copy myds.ds`,
``,
`dsply xxfield1;`,
``,
`return`,
].join(`\n`);

const parser = new Parser();
const cache = await parser.getDocs(URI, lines);
const { errors } = Linter.getErrors(lines, {
IncorrectVariableCase: true
}, cache);

assert.strictEqual(errors.length, 1, `Expect one errors`);
},

fixed1: async () => {
Expand Down Expand Up @@ -2020,5 +2042,31 @@ module.exports = {
assert.strictEqual(parmInputDs.name, `inputDS`);
assert.strictEqual(parmInputDs.position.line, 11);
assert.strictEqual(parmInputDs.subItems.length, 2);
}
},

// eof1: async () => {
// const lines = [
// ` D UPPERCASE PR 4096 Varying`,
// ` D String 4096 Const Varying`,
// ` D Escaped n Const Options(*NoPass)`,
// ` /EoF`,
// ` Converts all of the letters in String to their`,
// ` UPPER CASE equivalents. Non-alphabetic characters`,
// ` remain unchanged.`,
// ``,
// ` Escaped = *ON = converts characters that would crash iPDF and`,
// ` HTML to approximately equivalent characters.`,
// ` For example, translate " and ' to \` .`,
// ` (Default)`,
// ` *OFF= Do not convert any characters other than A-Z.`,
// ].join(`\n`);

// const parser = new Parser();
// const cache = await parser.getDocs(URI, lines);

// const uppercase = cache.find(`UPPERCASE`);
// assert.strictEqual(uppercase.name, `UPPERCASE`);
// assert.strictEqual(uppercase.position.line, 0);
// assert.strictEqual(uppercase.subItems, 2);
// }
}

0 comments on commit 63ed189

Please sign in to comment.