diff --git a/__tests__/parser-test.ts b/__tests__/parser-test.ts index 982b784..3abe591 100644 --- a/__tests__/parser-test.ts +++ b/__tests__/parser-test.ts @@ -5,7 +5,7 @@ function getMethod(methodString: string): parser.Method | undefined { const d = parser.parseText(methodString); return d.methods[0]; } -function getParsedDoc(documentString: string): parser.ParsedDocument { +function getParsedPsl(documentString: string): parser.ParsedPsl { return parser.parseText(documentString); } @@ -33,7 +33,7 @@ describe('Batch label', () => { // ~p1 source not set up if ER set RM = $$^MSG(1184,"BOFF-ACCUPD"), %BatchExit = 1 do EXC quit`; - const d = getParsedDoc(batchText); + const d = getParsedPsl(batchText); expect(d.methods).toHaveLength(1); }); @@ -93,7 +93,7 @@ describe('Method Identifiers', () => { test('Label from document', () => { const methodString = 'main\r\n'; - const result = getParsedDoc(methodString); + const result = getParsedPsl(methodString); if (!result) { fail(); return; @@ -347,13 +347,13 @@ describe('Argument Types', () => { describe('Propertydefs', () => { test('empty propertydef', () => { const propertyString = '\t#PROPERTYDEF'; - const doc = getParsedDoc(propertyString); + const doc = getParsedPsl(propertyString); expect(doc.properties).toHaveLength(0); }); test('one word propertydef', () => { const propertyString = '\t#PROPERTYDEF test'; - const doc = getParsedDoc(propertyString); + const doc = getParsedPsl(propertyString); expect(doc.properties).toHaveLength(1); }); }); @@ -394,7 +394,7 @@ public final String toString(String vMask) quit `; - const doc = getParsedDoc(documentString); + const doc = getParsedPsl(documentString); expect(doc.methods).toHaveLength(3); }); @@ -416,7 +416,7 @@ public final Integer toInteger() quit `; - const doc = getParsedDoc(documentString); + const doc = getParsedPsl(documentString); expect(doc.extending.value).toBe('Primitive'); }); @@ -438,7 +438,7 @@ public final Integer 900() quit `; - const doc = getParsedDoc(documentString); + const doc = getParsedPsl(documentString); expect(doc.methods[0].id.value).toBe('900'); }); @@ -478,7 +478,7 @@ public final String toString(String vMask) quit `; - const doc = getParsedDoc(documentString); + const doc = getParsedPsl(documentString); expect(doc.methods.map(method => method.line)).toEqual([9, 18, 27]); }); @@ -518,7 +518,7 @@ toString quit `; - const doc = getParsedDoc(documentString); + const doc = getParsedPsl(documentString); expect(doc.methods.map(method => method.id.value)).toEqual(['toInteger', 'toNumber', 'toString']); expect(doc.methods.map(method => method.line)).toEqual([9, 18, 27]); }); @@ -561,7 +561,7 @@ public final String toString(String vMask) quit `; - const doc = getParsedDoc(documentString); + const doc = getParsedPsl(documentString); expect(doc.methods).toHaveLength(3); }); @@ -603,7 +603,7 @@ public final String toString(String vMask) quit `; - const doc = getParsedDoc(documentString); + const doc = getParsedPsl(documentString); expect(doc.properties).toHaveLength(1); }); @@ -646,7 +646,7 @@ public final String toString(String vMask) quit `; - const doc = getParsedDoc(documentString); + const doc = getParsedPsl(documentString); expect(toValues(doc.properties[0].modifiers)).toEqual(['public']); expect(doc.properties[0].id.value).toEqual('test'); @@ -655,13 +655,13 @@ public final String toString(String vMask) describe('type declarations', () => { test('basic type declaration', () => { const declarationString = '\ttype public literal String x = "hi there"'; - const doc = getParsedDoc(declarationString); + const doc = getParsedPsl(declarationString); expect(doc.declarations[0].types[0].value).toEqual('String'); expect(doc.declarations[0].id.value).toEqual('x'); }); test('mutliple type declaration', () => { const declarationString = '\ttype public literal String x,y'; - const doc = getParsedDoc(declarationString); + const doc = getParsedPsl(declarationString); expect(doc.declarations[0].types[0].value).toEqual('String'); expect(doc.declarations[0].id.value).toEqual('x'); expect(doc.declarations[1].types[0].value).toEqual('String'); @@ -669,7 +669,7 @@ describe('type declarations', () => { }); test('mutliple multitype type declaration', () => { const declarationString = '\ttype public literal String x(Number,Boolean),y'; - const doc = getParsedDoc(declarationString); + const doc = getParsedPsl(declarationString); expect(doc.declarations[0].types[0].value).toEqual('String'); expect(doc.declarations[0].types[1].value).toEqual('Number'); expect(doc.declarations[0].types[2].value).toEqual('Boolean'); @@ -679,7 +679,7 @@ describe('type declarations', () => { }); test('mutliple type declaration equal sign', () => { const declarationString = '\ttype String x = "hi", y = "hi"'; - const doc = getParsedDoc(declarationString); + const doc = getParsedPsl(declarationString); expect(doc.declarations[0].types[0].value).toEqual('String'); expect(doc.declarations[0].id.value).toEqual('x'); expect(doc.declarations[1].types[0].value).toEqual('String'); @@ -687,13 +687,13 @@ describe('type declarations', () => { }); test('static type declaration', () => { const declarationString = '\ttype static x'; - const doc = getParsedDoc(declarationString); + const doc = getParsedPsl(declarationString); expect(doc.declarations[0].types[0].value).toEqual('x'); expect(doc.declarations[0].id.value).toEqual('x'); }); test('type type declaration', () => { const declarationString = '\ttype String type'; - const doc = getParsedDoc(declarationString); + const doc = getParsedPsl(declarationString); expect(doc.declarations[0].types[0].value).toEqual('String'); expect(doc.declarations[0].id.value).toEqual('type'); }); @@ -708,7 +708,7 @@ public static void main2() type Number y quit `; - const doc = getParsedDoc(documentString); + const doc = getParsedPsl(documentString); expect(doc.methods[0].declarations[0].id.value).toEqual('x'); expect(doc.methods[1].declarations[0].id.value).toEqual('y'); }); diff --git a/__tests__/utilities-test.ts b/__tests__/utilities-test.ts index 327e54a..c909015 100644 --- a/__tests__/utilities-test.ts +++ b/__tests__/utilities-test.ts @@ -1,5 +1,5 @@ import * as path from 'path'; -import { MemberClass, ParsedDocument, parseFile } from '../src/parser/parser'; +import { MemberClass, ParsedPsl, parseFile } from '../src/parser/parser'; import * as tokenizer from '../src/parser/tokenizer'; import * as utilities from '../src/parser/utilities'; @@ -121,8 +121,8 @@ describe('ParsedDocFinder', () => { let parentFilePath: string; let childFilePath: string; - let parsedParent: ParsedDocument; - let parsedChild: ParsedDocument; + let parsedParent: ParsedPsl; + let parsedChild: ParsedPsl; beforeAll(async () => { filesDir = path.resolve('__tests__', 'files'); diff --git a/src/language/codeQuality.ts b/src/language/codeQuality.ts index 6443a3b..e6eb9a9 100644 --- a/src/language/codeQuality.ts +++ b/src/language/codeQuality.ts @@ -102,9 +102,9 @@ function lint( lintDiagnostics: vscode.DiagnosticCollection, ) { const profileComponent: api.ProfileComponent = prepareDocument(textDocument); - const parsedDocument = api.ProfileComponent.isPsl(profileComponent.fsPath) ? + const parsedPsl = api.ProfileComponent.isPsl(profileComponent.fsPath) ? parser.parseText(textDocument.getText()) : undefined; - const diagnostics = getDiagnostics(profileComponent, parsedDocument, useConfig); + const diagnostics = getDiagnostics(profileComponent, parsedPsl, useConfig); const memberDiagnostics = transform(diagnostics, textDocument.uri); process.nextTick(() => { if (!cancellationToken.isCancellationRequested) { diff --git a/src/parser/parser.ts b/src/parser/parser.ts index a2cc8f1..5cf4f16 100644 --- a/src/parser/parser.ts +++ b/src/parser/parser.ts @@ -148,7 +148,7 @@ export interface Declaration extends Member { /** * An abstract syntax tree of a PSL document */ -export interface ParsedDocument { +export interface ParsedPsl { /** * An array of Declarations that are not contained within a method. @@ -239,12 +239,12 @@ export const NON_TYPE_MODIFIERS = [ 'public', 'static', 'private', ]; -export function parseText(sourceText: string): ParsedDocument { +export function parseText(sourceText: string): ParsedPsl { const parser = new Parser(); - return parser.parseDocument(sourceText); + return parser.parsePsl(sourceText); } -export function parseFile(sourcePath: string): Promise { +export function parseFile(sourcePath: string): Promise { return new Promise((resolve, reject) => { fs.readFile(sourcePath, (err, data) => { if (err) { @@ -252,7 +252,7 @@ export function parseFile(sourcePath: string): Promise { } else { const parser = new Parser(); - resolve(parser.parseDocument(data.toString())); + resolve(parser.parsePsl(data.toString())); } }); }); @@ -280,7 +280,7 @@ class Parser { if (tokenizer) this.tokenizer = tokenizer; } - parseDocument(documentText: string): ParsedDocument { + parsePsl(documentText: string): ParsedPsl { this.tokenizer = getTokens(documentText); while (this.next()) { if (this.activeToken.isAlphanumeric() || this.activeToken.isMinusSign()) { diff --git a/src/parser/utilities.ts b/src/parser/utilities.ts index af052fd..26abe72 100644 --- a/src/parser/utilities.ts +++ b/src/parser/utilities.ts @@ -1,6 +1,6 @@ import * as fs from 'fs-extra'; import * as path from 'path'; -import { Member, MemberClass, Method, ParsedDocument, parseText, Property } from './parser'; +import { Member, MemberClass, Method, ParsedPsl, parseText, Property } from './parser'; import { Position, Token, Type } from './tokenizer'; export interface FinderResult { @@ -18,18 +18,18 @@ export const dummyPosition = new Position(0, 0); export class ParsedDocFinder { - parsedDocument: ParsedDocument; + parsedPsl: ParsedPsl; paths: FinderPaths; procName: string; private hierarchy: string[] = []; constructor( - parsedDocument: ParsedDocument, + parsedPsl: ParsedPsl, paths: FinderPaths, getWorkspaceDocumentText?: (fsPath: string) => Promise, ) { - this.parsedDocument = parsedDocument; + this.parsedPsl = parsedPsl; this.paths = paths; if (getWorkspaceDocumentText) this.getWorkspaceDocumentText = getWorkspaceDocumentText; this.procName = path.basename(this.paths.routine).split('.')[0]; @@ -58,7 +58,7 @@ export class ParsedDocFinder { fsPath: tableLocation, }; } - else if (callTokens[0] === this.parsedDocument.extending) { + else if (callTokens[0] === this.parsedPsl.extending) { finder = await finder.newFinder(callTokens[0].value); return { fsPath: finder.paths.routine, @@ -135,7 +135,7 @@ export class ParsedDocFinder { }; return ret; }); - const parsedDocument: ParsedDocument = { + const parsedPsl: ParsedPsl = { comments: [], declarations: [], extending: new Token(Type.Alphanumeric, 'Record', dummyPosition), @@ -145,7 +145,7 @@ export class ParsedDocFinder { }; const newPaths: FinderPaths = Object.create(this.paths); newPaths.routine = tableDirectory; - return new ParsedDocFinder(parsedDocument, newPaths, this.getWorkspaceDocumentText); + return new ParsedDocFinder(parsedPsl, newPaths, this.getWorkspaceDocumentText); } const pathsWithoutExtensions: string[] = this.paths.projectPsl.map(pslPath => path.join(pslPath, routineName)); @@ -176,7 +176,7 @@ export class ParsedDocFinder { async searchInDocument(queriedId: string): Promise { let foundProperty; if (path.relative(this.paths.routine, this.paths.table) === '..') { - foundProperty = this.parsedDocument.properties.find(p => p.id.value.toLowerCase() === queriedId.toLowerCase()); + foundProperty = this.parsedPsl.properties.find(p => p.id.value.toLowerCase() === queriedId.toLowerCase()); if (foundProperty) { const tableName = path.basename(this.paths.routine).toUpperCase(); return { @@ -185,14 +185,14 @@ export class ParsedDocFinder { }; } } - foundProperty = this.parsedDocument.properties.find(p => p.id.value === queriedId); + foundProperty = this.parsedPsl.properties.find(p => p.id.value === queriedId); if (foundProperty) return { member: foundProperty, fsPath: this.paths.routine }; - const foundMethod = this.parsedDocument.methods.find(p => p.id.value === queriedId); + const foundMethod = this.parsedPsl.methods.find(p => p.id.value === queriedId); if (foundMethod) return { member: foundMethod, fsPath: this.paths.routine }; - if (this.parsedDocument.extending) { - const parentRoutineName = this.parsedDocument.extending.value; + if (this.parsedPsl.extending) { + const parentRoutineName = this.parsedPsl.extending.value; if (this.hierarchy.indexOf(parentRoutineName) > -1) return; const parentFinder: ParsedDocFinder | undefined = await this.searchForParent(parentRoutineName); if (!parentFinder) return; @@ -210,21 +210,21 @@ export class ParsedDocFinder { }; if (path.relative(this.paths.routine, this.paths.table) === '..') { - this.parsedDocument.properties.forEach(property => { + this.parsedPsl.properties.forEach(property => { const tableName = path.basename(this.paths.routine).toUpperCase(); addToResults({ member: property, fsPath: path.join(this.paths.routine, `${tableName}-${property.id.value}.COL`) }); }); } - this.parsedDocument.properties.forEach(property => { + this.parsedPsl.properties.forEach(property => { addToResults({ member: property, fsPath: this.paths.routine }); }); - this.parsedDocument.methods.forEach(method => { + this.parsedPsl.methods.forEach(method => { addToResults({ member: method, fsPath: this.paths.routine }); }); - if (this.parsedDocument.extending) { - const parentRoutineName = this.parsedDocument.extending.value; + if (this.parsedPsl.extending) { + const parentRoutineName = this.parsedPsl.extending.value; if (this.hierarchy.indexOf(parentRoutineName) > -1) return results; const parentFinder: ParsedDocFinder | undefined = await this.searchForParent(parentRoutineName); if (!parentFinder) return results; @@ -251,7 +251,7 @@ export class ParsedDocFinder { } private findActiveMethod(queriedToken: Token): Method | undefined { - const methods = this.parsedDocument.methods.filter(method => queriedToken.position.line >= method.id.position.line); + const methods = this.parsedPsl.methods.filter(method => queriedToken.position.line >= method.id.position.line); if (methods) return methods[methods.length - 1]; } @@ -401,8 +401,8 @@ export function getLineAfter(method: Method): number { return method.closeParen ? method.closeParen.position.line + 1 : method.id.position.line + 1; } -export function getCommentsOnLine(parsedDocument: ParsedDocument, lineNumber: number): Token[] { - return parsedDocument.comments.filter(t => { +export function getCommentsOnLine(parsedPsl: ParsedPsl, lineNumber: number): Token[] { + return parsedPsl.comments.filter(t => { return t.position.line === lineNumber; }); } diff --git a/src/pslLint/activate.ts b/src/pslLint/activate.ts index e688f8e..df2db3a 100644 --- a/src/pslLint/activate.ts +++ b/src/pslLint/activate.ts @@ -8,7 +8,7 @@ import { getConfig, matchConfig } from './config'; /** * Import rules here. */ -import { ParsedDocument } from '../parser/parser'; +import { ParsedPsl } from '../parser/parser'; import { MemberCamelCase, MemberLength, MemberLiteralCase, MemberStartsWithV, PropertyIsDummy, @@ -52,10 +52,10 @@ const parameterRules: ParameterRule[] = []; export function getDiagnostics( profileComponent: ProfileComponent, - parsedDocument?: ParsedDocument, + parsedPsl?: ParsedPsl, useConfig?: boolean, ): Diagnostic[] { - const subscription = new RuleSubscription(profileComponent, parsedDocument, useConfig); + const subscription = new RuleSubscription(profileComponent, parsedPsl, useConfig); return subscription.reportRules(); } @@ -74,7 +74,7 @@ class RuleSubscription { private declarationRules: DeclarationRule[]; private parameterRules: ParameterRule[]; - constructor(private profileComponent: ProfileComponent, private parsedDocument?: ParsedDocument, useConfig?: boolean) { + constructor(private profileComponent: ProfileComponent, private parsedPsl?: ParsedPsl, useConfig?: boolean) { this.diagnostics = []; const config = useConfig ? getConfig(this.profileComponent.fsPath) : undefined; @@ -90,9 +90,9 @@ class RuleSubscription { }; const initializePslRules = (rules: PslRule[]) => { const componentInitialized = initializeRules(rules) as PslRule[]; - const pslParsedDocument = this.parsedDocument as ParsedDocument; + const parsedPslDocument = this.parsedPsl as ParsedPsl; return componentInitialized.map(rule => { - rule.parsedDocument = pslParsedDocument; + rule.parsedPsl = parsedPslDocument; return rule; }); }; @@ -121,19 +121,19 @@ class RuleSubscription { if (ProfileComponent.isPsl(this.profileComponent.fsPath)) { addDiagnostics(this.pslRules); - const parsedDocument = this.parsedDocument as ParsedDocument; + const parsedPsl = this.parsedPsl as ParsedPsl; - for (const property of parsedDocument.properties) { + for (const property of parsedPsl.properties) { addDiagnostics(this.memberRules, property); addDiagnostics(this.propertyRules, property); } - for (const declaration of parsedDocument.declarations) { + for (const declaration of parsedPsl.declarations) { addDiagnostics(this.memberRules, declaration); addDiagnostics(this.declarationRules, declaration); } - for (const method of parsedDocument.methods) { + for (const method of parsedPsl.methods) { addDiagnostics(this.memberRules, method); addDiagnostics(this.methodRules, method); diff --git a/src/pslLint/api.ts b/src/pslLint/api.ts index fcbae73..b8cb519 100644 --- a/src/pslLint/api.ts +++ b/src/pslLint/api.ts @@ -1,5 +1,5 @@ import * as path from 'path'; -import { Declaration, Member, Method, Parameter, ParsedDocument, Property } from './../parser/parser'; +import { Declaration, Member, Method, Parameter, ParsedPsl, Property } from './../parser/parser'; import { Position, Range } from './../parser/tokenizer'; export enum DiagnosticSeverity { @@ -124,7 +124,7 @@ export abstract class FileDefinitionRule extends ProfileComponentRule { } export abstract class PslRule extends ProfileComponentRule { - parsedDocument: ParsedDocument; + parsedPsl: ParsedPsl; abstract report(...args: any[]): Diagnostic[]; } diff --git a/src/pslLint/cli/cli.ts b/src/pslLint/cli/cli.ts index 81ab126..4f07301 100644 --- a/src/pslLint/cli/cli.ts +++ b/src/pslLint/cli/cli.ts @@ -49,10 +49,10 @@ async function readFile(filename: string): Promise { return errorCount; } const textDocument = (await fs.readFile(fsPath)).toString(); - const parsedDocument = ProfileComponent.isPsl(fsPath) ? parseText(textDocument) : undefined; + const parsedPsl = ProfileComponent.isPsl(fsPath) ? parseText(textDocument) : undefined; const profileComponent = new ProfileComponent(fsPath, textDocument); - const diagnostics = getDiagnostics(profileComponent, parsedDocument, useConfig); + const diagnostics = getDiagnostics(profileComponent, parsedPsl, useConfig); diagnostics.forEach(diagnostic => { if (diagnostic.severity === DiagnosticSeverity.Warning || diagnostic.severity === DiagnosticSeverity.Error) { diff --git a/src/pslLint/elementsConventionChecker.ts b/src/pslLint/elementsConventionChecker.ts index 9eafa45..1c8d26e 100644 --- a/src/pslLint/elementsConventionChecker.ts +++ b/src/pslLint/elementsConventionChecker.ts @@ -29,7 +29,7 @@ export class PropertyIsDummy extends PropertyRule { report(property: Property): Diagnostic[] { const diagnostics: Diagnostic[] = []; - if (!this.parsedDocument.extending) { + if (!this.parsedPsl.extending) { this.isCalledDummy(property, diagnostics); } return diagnostics; diff --git a/src/pslLint/methodDoc.ts b/src/pslLint/methodDoc.ts index c48e851..517cc86 100644 --- a/src/pslLint/methodDoc.ts +++ b/src/pslLint/methodDoc.ts @@ -1,6 +1,6 @@ -import { Method, ParsedDocument } from '../parser/parser'; +import { Method, ParsedPsl } from '../parser/parser'; import { Token } from '../parser/tokenizer'; -import { getCommentsOnLine, getLineAfter} from '../parser/utilities'; +import { getCommentsOnLine, getLineAfter } from '../parser/utilities'; import { Diagnostic, DiagnosticSeverity, MethodRule } from './api'; export enum Code { @@ -19,7 +19,7 @@ export class MethodDocumentation extends MethodRule { const diagnostics: Diagnostic[] = []; - if (!hasBlockComment(method, this.parsedDocument)) { + if (!hasBlockComment(method, this.parsedPsl)) { const idToken = method.id; const message = `Documentation missing for label "${idToken.value}".`; diagnostics.push(addDiagnostic(idToken, method, message, this.ruleName)); @@ -36,7 +36,7 @@ export class MethodSeparator extends MethodRule { const diagnostics: Diagnostic[] = []; - if (!hasSeparator(method, this.parsedDocument)) { + if (!hasSeparator(method, this.parsedPsl)) { const idToken = method.id; const message = `Separator missing for label "${idToken.value}".`; diagnostics.push(addDiagnostic(idToken, method, message, this.ruleName)); @@ -55,7 +55,7 @@ export class TwoEmptyLines extends MethodRule { const diagnostics: Diagnostic[] = []; const idToken = method.id; - const lineAbove = hasSeparator(method, this.parsedDocument) ? + const lineAbove = hasSeparator(method, this.parsedPsl) ? method.id.position.line - 2 : method.id.position.line - 1; if (lineAbove < 2) { @@ -96,12 +96,12 @@ function addDiagnostic(idToken: Token, method: Method, message: string, ruleName return diagnostic; } -function hasSeparator(method: Method, parsedDocument: ParsedDocument): boolean { - const nextLineCommentTokens: Token[] = getCommentsOnLine(parsedDocument, method.id.position.line - 1); +function hasSeparator(method: Method, parsedPsl: ParsedPsl): boolean { + const nextLineCommentTokens: Token[] = getCommentsOnLine(parsedPsl, method.id.position.line - 1); return nextLineCommentTokens[0] && nextLineCommentTokens[0].isLineComment(); } -function hasBlockComment(method: Method, parsedDocument: ParsedDocument): boolean { - const nextLineCommentTokens: Token[] = getCommentsOnLine(parsedDocument, getLineAfter(method)); +function hasBlockComment(method: Method, parsedPsl: ParsedPsl): boolean { + const nextLineCommentTokens: Token[] = getCommentsOnLine(parsedPsl, getLineAfter(method)); return nextLineCommentTokens[0] && nextLineCommentTokens[0].isBlockComment(); } diff --git a/src/pslLint/runtime.ts b/src/pslLint/runtime.ts index 5305a20..025a816 100644 --- a/src/pslLint/runtime.ts +++ b/src/pslLint/runtime.ts @@ -69,7 +69,7 @@ export class RuntimeStart extends MethodRule { const startLine = lastStart.id.position.line; const commitLine = runtimeMethod.id.position.line; const identifierTokens: Token[] = this.getAllIdentifersInRange( - this.parsedDocument.tokens, + this.parsedPsl.tokens, startLine, commitLine, ); @@ -155,7 +155,7 @@ export class RuntimeStart extends MethodRule { private addToWhitelist(runtimeMethod: Identifier) { let acceptVariables: string[] = []; - const commentsAbove: Token[] = getCommentsOnLine(this.parsedDocument, runtimeMethod.id.position.line - 1); + const commentsAbove: Token[] = getCommentsOnLine(this.parsedPsl, runtimeMethod.id.position.line - 1); const whiteListComment = commentsAbove[0]; if (!whiteListComment || !whiteListComment.isLineComment()) return []; diff --git a/src/pslLint/todos.ts b/src/pslLint/todos.ts index 2bb7466..32eaafb 100644 --- a/src/pslLint/todos.ts +++ b/src/pslLint/todos.ts @@ -5,7 +5,7 @@ export class TodoInfo extends PslRule { report(): Diagnostic[] { let todos: Todo[] = []; - for (const token of this.parsedDocument.comments) { + for (const token of this.parsedPsl.comments) { if (token.value.includes('TODO')) { const startLine = token.position.line; const startChar = token.position.character;