From ecd84962d7081add41b3ada076238c2de06ffb19 Mon Sep 17 00:00:00 2001 From: Alexander Tiplea Date: Sun, 9 Dec 2018 22:31:35 +0100 Subject: [PATCH 1/8] Intitialize rules every time --- src/pslLint/activate.ts | 77 ++++++++++++++++++++++------------------- tslint.json | 3 +- 2 files changed, 43 insertions(+), 37 deletions(-) diff --git a/src/pslLint/activate.ts b/src/pslLint/activate.ts index e688f8e..06d1168 100644 --- a/src/pslLint/activate.ts +++ b/src/pslLint/activate.ts @@ -20,35 +20,39 @@ import { RuntimeStart } from './runtime'; import { TblColDocumentation } from './tblcolDoc'; import { TodoInfo } from './todos'; +interface Constructor { + new (): T; +} + /** * Add new rules here to have them checked at the appropriate time. */ -const componentRules: ProfileComponentRule[] = []; -const fileDefinitionRules: FileDefinitionRule[] = [ - new TblColDocumentation(), +const componentRuleConstructors: Constructor[] = []; +const fileDefinitionRuleConstructors: Constructor[] = [ + TblColDocumentation, ]; -const pslRules: PslRule[] = [ - new TodoInfo(), +const pslRuleConstructors: Constructor[] = [ + TodoInfo, ]; -const memberRules: MemberRule[] = [ - new MemberCamelCase(), - new MemberLength(), - new MemberStartsWithV(), - new MemberLiteralCase(), +const memberRuleConstructors: Constructor[] = [ + MemberCamelCase, + MemberLength, + MemberStartsWithV, + MemberLiteralCase, ]; -const methodRules: MethodRule[] = [ - new MethodDocumentation(), - new MethodSeparator(), - new MethodParametersOnNewLine(), - new RuntimeStart(), - new MultiLineDeclare(), - new TwoEmptyLines(), +const methodRuleConstructors: Constructor[] = [ + MethodDocumentation, + MethodSeparator, + MethodParametersOnNewLine, + RuntimeStart, + MultiLineDeclare, + TwoEmptyLines, ]; -const propertyRules: PropertyRule[] = [ - new PropertyIsDummy(), +const propertyRuleConstructors: Constructor[] = [ + PropertyIsDummy, ]; -const declarationRules: DeclarationRule[] = []; -const parameterRules: ParameterRule[] = []; +const declarationRuleConstructors: Constructor[] = []; +const parameterRuleConstructors: Constructor[] = []; export function getDiagnostics( profileComponent: ProfileComponent, @@ -79,17 +83,18 @@ class RuleSubscription { const config = useConfig ? getConfig(this.profileComponent.fsPath) : undefined; - const initializeRules = (rules: ProfileComponentRule[]) => { - return rules.filter(rule => { - if (!config) return true; - return matchConfig(path.basename(this.profileComponent.fsPath), rule.ruleName, config); - }).map(rule => { + const initializeRules = (ruleCtors: Constructor[]) => { + return ruleCtors.map(ruleCtor => { + const rule = new ruleCtor(); rule.profileComponent = this.profileComponent; return rule; + }).filter(rule => { + if (!config) return true; + return matchConfig(path.basename(this.profileComponent.fsPath), rule.ruleName, config); }); }; - const initializePslRules = (rules: PslRule[]) => { - const componentInitialized = initializeRules(rules) as PslRule[]; + const initializePslRules = (ruleCtor: Constructor[]) => { + const componentInitialized = initializeRules(ruleCtor) as PslRule[]; const pslParsedDocument = this.parsedDocument as ParsedDocument; return componentInitialized.map(rule => { rule.parsedDocument = pslParsedDocument; @@ -97,14 +102,14 @@ class RuleSubscription { }); }; - this.componentRules = initializeRules(componentRules); - this.fileDefinitionRules = initializeRules(fileDefinitionRules); - this.pslRules = initializePslRules(pslRules); - this.methodRules = initializePslRules(methodRules); - this.memberRules = initializePslRules(memberRules); - this.propertyRules = initializePslRules(propertyRules); - this.declarationRules = initializePslRules(declarationRules); - this.parameterRules = initializePslRules(parameterRules); + this.componentRules = initializeRules(componentRuleConstructors); + this.fileDefinitionRules = initializeRules(fileDefinitionRuleConstructors); + this.pslRules = initializePslRules(pslRuleConstructors); + this.methodRules = initializePslRules(methodRuleConstructors); + this.memberRules = initializePslRules(memberRuleConstructors); + this.propertyRules = initializePslRules(propertyRuleConstructors); + this.declarationRules = initializePslRules(declarationRuleConstructors); + this.parameterRules = initializePslRules(parameterRuleConstructors); } reportRules(): Diagnostic[] { diff --git a/tslint.json b/tslint.json index 881607c..40efb64 100644 --- a/tslint.json +++ b/tslint.json @@ -43,7 +43,8 @@ ], "no-console": [ false - ] + ], + "array-type": [true, "array"] }, "defaultSeverity": "warn" } From ce3e51199546dbb133cd45002108e4264d5e6322 Mon Sep 17 00:00:00 2001 From: Alexander Tiplea Date: Sun, 9 Dec 2018 22:39:50 +0100 Subject: [PATCH 2/8] Remove diagnostics as instance variable --- src/pslLint/activate.ts | 40 ++++++++++++++++++---------------------- 1 file changed, 18 insertions(+), 22 deletions(-) diff --git a/src/pslLint/activate.ts b/src/pslLint/activate.ts index 06d1168..a546509 100644 --- a/src/pslLint/activate.ts +++ b/src/pslLint/activate.ts @@ -63,12 +63,8 @@ export function getDiagnostics( return subscription.reportRules(); } -/** - * Interface for adding and executing rules. - */ class RuleSubscription { - private diagnostics: Diagnostic[]; private componentRules: ProfileComponentRule[]; private pslRules: PslRule[]; private fileDefinitionRules: FileDefinitionRule[]; @@ -79,8 +75,6 @@ class RuleSubscription { private parameterRules: ParameterRule[]; constructor(private profileComponent: ProfileComponent, private parsedDocument?: ParsedDocument, useConfig?: boolean) { - this.diagnostics = []; - const config = useConfig ? getConfig(this.profileComponent.fsPath) : undefined; const initializeRules = (ruleCtors: Constructor[]) => { @@ -113,48 +107,50 @@ class RuleSubscription { } reportRules(): Diagnostic[] { - const addDiagnostics = (rules: ProfileComponentRule[], ...args: any[]) => { - rules.forEach(rule => this.diagnostics.push(...rule.report(...args))); + const diagnostics: Diagnostic[] = []; + + const collectDiagnostics = (rules: ProfileComponentRule[], ...args: any[]) => { + rules.forEach(rule => diagnostics.push(...rule.report(...args))); }; - addDiagnostics(this.componentRules); + collectDiagnostics(this.componentRules); if (ProfileComponent.isFileDefinition(this.profileComponent.fsPath)) { - addDiagnostics(this.fileDefinitionRules); + collectDiagnostics(this.fileDefinitionRules); } if (ProfileComponent.isPsl(this.profileComponent.fsPath)) { - addDiagnostics(this.pslRules); + collectDiagnostics(this.pslRules); const parsedDocument = this.parsedDocument as ParsedDocument; for (const property of parsedDocument.properties) { - addDiagnostics(this.memberRules, property); - addDiagnostics(this.propertyRules, property); + collectDiagnostics(this.memberRules, property); + collectDiagnostics(this.propertyRules, property); } for (const declaration of parsedDocument.declarations) { - addDiagnostics(this.memberRules, declaration); - addDiagnostics(this.declarationRules, declaration); + collectDiagnostics(this.memberRules, declaration); + collectDiagnostics(this.declarationRules, declaration); } for (const method of parsedDocument.methods) { - addDiagnostics(this.memberRules, method); - addDiagnostics(this.methodRules, method); + collectDiagnostics(this.memberRules, method); + collectDiagnostics(this.methodRules, method); for (const parameter of method.parameters) { - addDiagnostics(this.memberRules, parameter); - addDiagnostics(this.parameterRules, parameter, method); + collectDiagnostics(this.memberRules, parameter); + collectDiagnostics(this.parameterRules, parameter, method); } for (const declaration of method.declarations) { - addDiagnostics(this.memberRules, declaration); - addDiagnostics(this.declarationRules, declaration, method); + collectDiagnostics(this.memberRules, declaration); + collectDiagnostics(this.declarationRules, declaration, method); } } } - return this.diagnostics; + return diagnostics; } } From 9f5ae383cb0248e932e91a921ff3cc1bacbbd3d7 Mon Sep 17 00:00:00 2001 From: Alexander Tiplea Date: Mon, 10 Dec 2018 16:05:23 +0100 Subject: [PATCH 3/8] Redesign constructors --- src/pslLint/activate.ts | 60 +++++++++++++++++------------------------ src/pslLint/api.ts | 36 +++++++++++++++++++++++++ 2 files changed, 60 insertions(+), 36 deletions(-) diff --git a/src/pslLint/activate.ts b/src/pslLint/activate.ts index a546509..b383df6 100644 --- a/src/pslLint/activate.ts +++ b/src/pslLint/activate.ts @@ -1,14 +1,12 @@ import * as path from 'path'; +import { ParsedDocument } from '../parser/parser'; import { - DeclarationRule, Diagnostic, FileDefinitionRule, MemberRule, MethodRule, ParameterRule, - ProfileComponent, ProfileComponentRule, PropertyRule, PslRule, + DeclarationRule, DeclarationRuleConstructor, Diagnostic, FileDefinitionRule, FileDefinitionRuleConstructor, + MemberRule, MemberRuleConstructor, MethodRule, MethodRuleConstructor, ParameterRule, ParameterRuleConstructor, + ProfileComponent, ProfileComponentRule, ProfileComponentRuleConstructor, PropertyRule, PropertyRuleConstructor, + PslRule, PslRuleConstructor, } from './api'; import { getConfig, matchConfig } from './config'; - -/** - * Import rules here. - */ -import { ParsedDocument } from '../parser/parser'; import { MemberCamelCase, MemberLength, MemberLiteralCase, MemberStartsWithV, PropertyIsDummy, @@ -20,27 +18,20 @@ import { RuntimeStart } from './runtime'; import { TblColDocumentation } from './tblcolDoc'; import { TodoInfo } from './todos'; -interface Constructor { - new (): T; -} - -/** - * Add new rules here to have them checked at the appropriate time. - */ -const componentRuleConstructors: Constructor[] = []; -const fileDefinitionRuleConstructors: Constructor[] = [ +const componentRuleConstructors: ProfileComponentRuleConstructor[] = []; +const fileDefinitionRuleConstructors: FileDefinitionRuleConstructor[] = [ TblColDocumentation, ]; -const pslRuleConstructors: Constructor[] = [ +const pslRuleConstructors: PslRuleConstructor[] = [ TodoInfo, ]; -const memberRuleConstructors: Constructor[] = [ +const memberRuleConstructors: MemberRuleConstructor[] = [ MemberCamelCase, MemberLength, MemberStartsWithV, MemberLiteralCase, ]; -const methodRuleConstructors: Constructor[] = [ +const methodRuleConstructors: MethodRuleConstructor[] = [ MethodDocumentation, MethodSeparator, MethodParametersOnNewLine, @@ -48,11 +39,11 @@ const methodRuleConstructors: Constructor[] = [ MultiLineDeclare, TwoEmptyLines, ]; -const propertyRuleConstructors: Constructor[] = [ +const propertyRuleConstructors: PropertyRuleConstructor[] = [ PropertyIsDummy, ]; -const declarationRuleConstructors: Constructor[] = []; -const parameterRuleConstructors: Constructor[] = []; +const declarationRuleConstructors: DeclarationRuleConstructor[] = []; +const parameterRuleConstructors: ParameterRuleConstructor[] = []; export function getDiagnostics( profileComponent: ProfileComponent, @@ -77,22 +68,19 @@ class RuleSubscription { constructor(private profileComponent: ProfileComponent, private parsedDocument?: ParsedDocument, useConfig?: boolean) { const config = useConfig ? getConfig(this.profileComponent.fsPath) : undefined; - const initializeRules = (ruleCtors: Constructor[]) => { - return ruleCtors.map(ruleCtor => { - const rule = new ruleCtor(); - rule.profileComponent = this.profileComponent; - return rule; - }).filter(rule => { - if (!config) return true; - return matchConfig(path.basename(this.profileComponent.fsPath), rule.ruleName, config); + const filterRule = (ruleCtor: ProfileComponentRuleConstructor | PslRuleConstructor) => { + if (!config) return true; + return matchConfig(path.basename(this.profileComponent.fsPath), ruleCtor.name, config); + }; + const initializeRules = (ruleCtors: ProfileComponentRuleConstructor[]) => { + return ruleCtors.filter(filterRule).map(ruleCtor => { + return new ruleCtor(this.profileComponent); }); }; - const initializePslRules = (ruleCtor: Constructor[]) => { - const componentInitialized = initializeRules(ruleCtor) as PslRule[]; - const pslParsedDocument = this.parsedDocument as ParsedDocument; - return componentInitialized.map(rule => { - rule.parsedDocument = pslParsedDocument; - return rule; + const initializePslRules = (ruleCtors: PslRuleConstructor[]) => { + return ruleCtors.filter(filterRule).map(ruleCtor => { + const pslParsedDocument = this.parsedDocument as ParsedDocument; + return new ruleCtor(this.profileComponent, pslParsedDocument); }); }; diff --git a/src/pslLint/api.ts b/src/pslLint/api.ts index fcbae73..c7641fc 100644 --- a/src/pslLint/api.ts +++ b/src/pslLint/api.ts @@ -117,6 +117,10 @@ export abstract class ProfileComponentRule { profileComponent: ProfileComponent; + constructor(profileComponent: ProfileComponent) { + this.profileComponent = profileComponent; + } + abstract report(...args: any[]): Diagnostic[]; } @@ -126,6 +130,11 @@ export abstract class PslRule extends ProfileComponentRule { parsedDocument: ParsedDocument; + constructor(profileComponent: ProfileComponent, parsedDocument: ParsedDocument) { + super(profileComponent); + this.parsedDocument = parsedDocument; + } + abstract report(...args: any[]): Diagnostic[]; } @@ -149,6 +158,33 @@ export abstract class DeclarationRule extends PslRule { abstract report(declaration: Declaration, method?: Method): Diagnostic[]; } +export type FileDefinitionRuleConstructor = new (profileComponent: ProfileComponent) => FileDefinitionRule; +export type ProfileComponentRuleConstructor = new (profileComponent: ProfileComponent) => ProfileComponentRule; +export type PslRuleConstructor = new ( + profileComponent: ProfileComponent, + parsedDocument: ParsedDocument, +) => PslRule; +export type MemberRuleConstructor = new ( + profileComponent: ProfileComponent, + parsedDocument: ParsedDocument, +) => MemberRule; +export type PropertyRuleConstructor = new ( + profileComponent: ProfileComponent, + parsedDocument: ParsedDocument, +) => PropertyRule; +export type MethodRuleConstructor = new ( + profileComponent: ProfileComponent, + parsedDocument: ParsedDocument, +) => MethodRule; +export type ParameterRuleConstructor = new ( + profileComponent: ProfileComponent, + parsedDocument: ParsedDocument, +) => ParameterRule; +export type DeclarationRuleConstructor = new ( + profileComponent: ProfileComponent, + parsedDocument: ParsedDocument, +) => DeclarationRule; + type GetTextMethod = (lineNumber: number) => string; /** From 07ae8dc856c504596908d57024a3e0dbf4c25b11 Mon Sep 17 00:00:00 2001 From: Alexander Tiplea Date: Wed, 12 Dec 2018 18:00:41 +0100 Subject: [PATCH 4/8] Correct behavior when using config but it's not present --- src/pslLint/activate.ts | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/pslLint/activate.ts b/src/pslLint/activate.ts index b383df6..7911677 100644 --- a/src/pslLint/activate.ts +++ b/src/pslLint/activate.ts @@ -69,7 +69,8 @@ class RuleSubscription { const config = useConfig ? getConfig(this.profileComponent.fsPath) : undefined; const filterRule = (ruleCtor: ProfileComponentRuleConstructor | PslRuleConstructor) => { - if (!config) return true; + if (!useConfig) return true; + if (!config) return false; return matchConfig(path.basename(this.profileComponent.fsPath), ruleCtor.name, config); }; const initializeRules = (ruleCtors: ProfileComponentRuleConstructor[]) => { From 9367268aea33f9a15c634347348c559d234cb96a Mon Sep 17 00:00:00 2001 From: Alexander Tiplea Date: Thu, 13 Dec 2018 10:54:58 +0100 Subject: [PATCH 5/8] Update documentation --- CHANGELOG.md | 5 +++++ README.md | 37 ++++++++++++++++++++++++++++++++----- src/pslLint/cli/README.md | 18 ++++++++++++++++++ 3 files changed, 55 insertions(+), 5 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 9fce32e..f71468e 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,6 +1,11 @@ # Change Log All notable changes to the "vscode-psl" extension will be documented in this file. +# v1.7.2 + +* Updates documentation about Code Quality and settings. +* By default, Code Quality via `psl-lint` will only activate when the `psl-lint.json` configuration file is present. + # v1.7.1 * public declarations that start with v are now only diagnosed at INFO level diff --git a/README.md b/README.md index 16d35f6..d085b88 100644 --- a/README.md +++ b/README.md @@ -6,9 +6,16 @@ Profile Scripting Language functionality for Visual Studio Code. ## Dependencies -* Visual Studio Code version 1.23.0 (April 2018) or higher +* Visual Studio Code version 1.23.0 (April 2018) or higher. -## Configuration +## Avaliable Settings + +* `psl.lint` Whether to lint files written in PSL. The default value is `config`, which means linting only activates when the `psl-lint.json` config file is present. [Read more here](#psl-lint). +* `psl.previewFeatures` Set true to enable the latest developing features (requires restart). Default value is false. +* `psl.trailingNewline` Adds a trailing newline after a "Get" or "Refresh". The default behavior is to not change the output. +* `psl.documentationServer` HTTP POST endpoint that responds with PSL documentation in markdown format. + +## Environment Configuration Locate the button at the bottom-right corner titled `Configure Environments`. If the button is not visible, use the Command Pallete (F1 or Ctrl+Shift+P) to find the `PSL: Configure Environment` command. A JSON object of the following form will appear: ```json @@ -37,20 +44,40 @@ The extension is able to communicate with Host via MRPC121 to do the following: * Test Compile .PROC and .PSL files * Compile and Link .PROC and .PSL files * Run .PROC and .PSL files +* [Code Quality checks via psl-lint](#psl-lint) These commands can be executed via the Command Pallette (F1 or Ctrl+Shift+P), icons at the top-right corner of the document, right-clicking the document, or right-clicking the file in the Side Bar Explorer. > Please note that the Host Commands are executed *asynchronously*, meaning that vscode will not require you to wait to finish one action before you start another. This may have unintended consequences if you do not wait. For example, you must wait for sending to finish before you compile and link. -Basic language features also exist for files written in PSL, data configuration, and table files. +Basic language features also exist for files written in PSL, data configuration, and table files. These features include: * Syntax coloring -* Property and Label outline for PSL files (access by Ctrl+Shift+O or with [this extension](https://marketplace.visualstudio.com/items?itemName=patrys.vscode-code-outline)) -* Auto-complete for Record objects in PSL (activated by the `.` operator or by Ctrl+Space) +* Property and Label outline for PSL files (access by Ctrl+Shift+O or by enabling the built-in outline). +* Code Completion, Hoves, and Go-To Definition by activating `psl.previewFeatures`. * Highlighting and Hover information for editing data configuration files * Code snippets for loops, comments, and table/column definitions +### psl-lint + +This extension includes support for checking PSL code against common standards. The setting `psl.lint` is by default set to `config`, meaning the linting module will activate upon finding a `psl-lint.json` configuration file. The format of the file is as follows: + +``` +{ + "version": 1, + "include": { + "Z*": ["*"], + "*": ["TodoInfo"] + }, + "exclude": { + "ZRPC*.PROC": ["MemberCamelCase"] + } +} +``` + +This example illustrates how the configuration file is defined. Within `include` and `exclude` are filename-to-rules mappings. The filenames can be glob patterns ("Z*" will match all files that start with Z). The rules are written in an array, and must be explicitly stated. The only exception is the "*" rule, which matches all rules. [For more information about which rules are available, and how the linting can be used outside of vscode, visit the package at npm](https://www.npmjs.com/package/psl-lint). + ## Development If you would like to join the development of this extension, you will need to install [node.js](https://nodejs.org/en/) (with NPM) in order to install the dependencies. diff --git a/src/pslLint/cli/README.md b/src/pslLint/cli/README.md index 3e68727..ccd84b7 100644 --- a/src/pslLint/cli/README.md +++ b/src/pslLint/cli/README.md @@ -20,6 +20,24 @@ This module works by adding rules that are automatically checked at the appropri * PropertyIsDummy * TblColDocumentation +## Configuration + +By creating a file `psl-lint.json` at the root of the project, you can control the behavior of the linter. The format of the file is as follows: + +``` +{ + "version": 1, + "include": { + "Z*": ["*"], + "*": ["TodoInfo"] + }, + "exclude": { + "ZRPC*.PROC": ["MemberCamelCase"] + } +} +``` + +Within `include` and `exclude` are filename-to-rules mappings. The filenames can be glob patterns ("Z*" will match all files that start with Z). The rules are written in an array, and must be explicitly stated. The only exception is the "*" rule, which matches all rules. ## Contributing From a9d460ac371350c7511d867f8261c9d412d9f363 Mon Sep 17 00:00:00 2001 From: Alexander Tiplea Date: Thu, 13 Dec 2018 12:25:24 +0100 Subject: [PATCH 6/8] Update READMEs --- README.md | 4 ++-- src/pslLint/cli/README.md | 6 +++--- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/README.md b/README.md index d085b88..9ada706 100644 --- a/README.md +++ b/README.md @@ -61,7 +61,7 @@ These features include: ### psl-lint -This extension includes support for checking PSL code against common standards. The setting `psl.lint` is by default set to `config`, meaning the linting module will activate upon finding a `psl-lint.json` configuration file. The format of the file is as follows: +This extension includes support for checking PSL code against common coding standards. The setting `psl.lint` is by default set to `config`, meaning the linting module will activate upon finding a `psl-lint.json` configuration file. The format of the file is as follows: ``` { @@ -80,7 +80,7 @@ This example illustrates how the configuration file is defined. Within `include` ## Development -If you would like to join the development of this extension, you will need to install [node.js](https://nodejs.org/en/) (with NPM) in order to install the dependencies. +If you would like to join the development of this extension, you will need to install [node.js](https://nodejs.org/en/) (with npm) in order to install the dependencies. Once you clone the project, from the command line in the root of this project, run `npm install`. diff --git a/src/pslLint/cli/README.md b/src/pslLint/cli/README.md index ccd84b7..d27b93a 100644 --- a/src/pslLint/cli/README.md +++ b/src/pslLint/cli/README.md @@ -14,15 +14,15 @@ This module works by adding rules that are automatically checked at the appropri * MethodParametersOnNewLine * MethodSeparator * MultiLineDeclare +* PropertyIsDummy * RuntimeStart +* TblColDocumentation * TodoInfo * TwoEmptyLines -* PropertyIsDummy -* TblColDocumentation ## Configuration -By creating a file `psl-lint.json` at the root of the project, you can control the behavior of the linter. The format of the file is as follows: +By creating a file `psl-lint.json` at the root of the project, you can control the behavior of the linter. The format of the file is as follows: ``` { From e46b6ba654384f77611fd328962875c4b8744c63 Mon Sep 17 00:00:00 2001 From: Alexander Tiplea Date: Mon, 21 Jan 2019 15:09:52 +0100 Subject: [PATCH 7/8] Documentation --- README.md | 10 ++++++---- src/pslLint/api.ts | 48 +++++++++++++++++++++++++++++++++++++++------- 2 files changed, 47 insertions(+), 11 deletions(-) diff --git a/README.md b/README.md index 1474c33..57e4956 100644 --- a/README.md +++ b/README.md @@ -28,8 +28,8 @@ Locate the button at the bottom-right corner titled `Configure Environments`. If "user": "", "password": "", "sshLogin": "", - "serverType": "SCA$IBS", // added v1.8.0 - "encoding": "utf8" // added v1.8.0 + "serverType": "SCA$IBS", + "encoding": "utf8" } ] } @@ -66,7 +66,7 @@ These features include: ### psl-lint -This extension includes support for checking PSL code against common coding standards. The setting `psl.lint` is by default set to `config`, meaning the linting module will activate upon finding a `psl-lint.json` configuration file. The format of the file is as follows: +This extension includes support for checking PSL against common coding standards. The setting `psl.lint` is by default set to `config`, meaning the linting module will activate upon finding a `psl-lint.json` configuration file. Here is a sample: ``` { @@ -81,7 +81,9 @@ This extension includes support for checking PSL code against common coding stan } ``` -This example illustrates how the configuration file is defined. Within `include` and `exclude` are filename-to-rules mappings. The filenames can be glob patterns ("Z*" will match all files that start with Z). The rules are written in an array, and must be explicitly stated. The only exception is the "*" rule, which matches all rules. [For more information about which rules are available, and how the linting can be used outside of vscode, visit the package at npm](https://www.npmjs.com/package/psl-lint). +Within `include` and `exclude` mappings from filename patterns to rules. These are glob-style patterns ("Z*" will match all files that start with Z). The rules are written in an array, and must be explicitly stated. The only exception is the "*" rule, which matches all rules. + +[For more information about which rules are available, and how the linting can be used outside of vscode, visit the package at npm](https://www.npmjs.com/package/psl-lint). ## Development diff --git a/src/pslLint/api.ts b/src/pslLint/api.ts index c7641fc..9a7acd3 100644 --- a/src/pslLint/api.ts +++ b/src/pslLint/api.ts @@ -113,8 +113,15 @@ export class DiagnosticRelatedInformation { export abstract class ProfileComponentRule { + /** + * The rule name as it is known in the `psl-lint.json` configuration. + * This is automatically the same as the rule class name. + */ readonly ruleName: string = this.constructor.name; + /** + * The current component being checked. + */ profileComponent: ProfileComponent; constructor(profileComponent: ProfileComponent) { @@ -128,6 +135,9 @@ export abstract class FileDefinitionRule extends ProfileComponentRule { } export abstract class PslRule extends ProfileComponentRule { + /** + * A parsed version of a PSL component. + */ parsedDocument: ParsedDocument; constructor(profileComponent: ProfileComponent, parsedDocument: ParsedDocument) { @@ -135,25 +145,36 @@ export abstract class PslRule extends ProfileComponentRule { this.parsedDocument = parsedDocument; } - abstract report(...args: any[]): Diagnostic[]; } +/** + * A rule that apply to a Property, Declaration, Parameter, or Method equally. + */ export abstract class MemberRule extends PslRule { abstract report(member: Member): Diagnostic[]; } +/** + * A rule that only apply to a Property. + */ export abstract class PropertyRule extends PslRule { abstract report(property: Property): Diagnostic[]; } - +/** + * A rule that only apply to a Method. + */ export abstract class MethodRule extends PslRule { abstract report(method: Method): Diagnostic[]; } - +/** + * A rule that only apply to a Parameter. + */ export abstract class ParameterRule extends PslRule { abstract report(parameter: Parameter, method: Method): Diagnostic[]; } - +/** + * A rule that only apply to a Declaration. + */ export abstract class DeclarationRule extends PslRule { abstract report(declaration: Declaration, method?: Method): Diagnostic[]; } @@ -192,25 +213,38 @@ type GetTextMethod = (lineNumber: number) => string; * The file may be PSL or non-PSL (such as a TBL or COL). */ export class ProfileComponent { - + /* + * Utility method to check a path. + */ static isPsl(fsPath: string): boolean { return path.extname(fsPath) === '.PROC' || path.extname(fsPath) === '.BATCH' || path.extname(fsPath) === '.TRIG' || path.extname(fsPath).toUpperCase() === '.PSL'; } - + /* + * Utility method to check a path. + */ static isFileDefinition(fsPath: string): boolean { return path.extname(fsPath) === '.TBL' || path.extname(fsPath) === '.COL'; } - + /* + * Utility method to check a path. + */ static isProfileComponent(fsPath: string): boolean { return ProfileComponent.isPsl(fsPath) || ProfileComponent.isFileDefinition(fsPath); } + /** + * The path on the file system to the component. + */ fsPath: string; + + /** + * The text contents of the component. + */ textDocument: string; private indexedDocument?: Map; From 2619daed30e367ea5791e8e9eb21337b1e3ea856 Mon Sep 17 00:00:00 2001 From: Alexander Tiplea Date: Mon, 21 Jan 2019 17:07:48 +0100 Subject: [PATCH 8/8] Documentation --- src/pslLint/activate.ts | 3 +++ 1 file changed, 3 insertions(+) diff --git a/src/pslLint/activate.ts b/src/pslLint/activate.ts index 7911677..bfcc246 100644 --- a/src/pslLint/activate.ts +++ b/src/pslLint/activate.ts @@ -54,6 +54,9 @@ export function getDiagnostics( return subscription.reportRules(); } +/** + * Manages which rules need to be applied to a given component. + */ class RuleSubscription { private componentRules: ProfileComponentRule[];