1
0
mirror of https://github.com/sasjs/lint.git synced 2025-12-10 17:34:36 +00:00

Compare commits

...

10 Commits

Author SHA1 Message Date
Allan Bowe
9623828fc8 Merge pull request #180 from sasjs/quick-fix
feat: add configuration as an optional argument for formatText
2022-11-08 14:48:44 +00:00
debeff7929 fix: updated sasjslint-schema.json 2022-11-08 19:43:18 +05:00
c210699954 feat: add configuration as an optional argument for formatText 2022-11-08 19:33:21 +05:00
Allan Bowe
cee30d0030 Merge pull request #179 from sasjs/issue-178
feat: customise the defaultHeader
2022-11-07 13:41:03 +00:00
Allan Bowe
66bcfb2962 fix: README 2022-11-07 12:30:31 +00:00
a3bade0a5a feat: customise the defaultHeader 2022-11-07 16:50:35 +05:00
Allan Bowe
1d821db934 Update sasjslint-schema.json 2022-08-16 00:13:15 +01:00
Allan Bowe
f3858d33fc Merge pull request #169 from sasjs/allanbowe/vs-code-error-when-adding-168
chore: updating docs for ignoreList
2022-08-16 00:10:28 +01:00
Allan Bowe
0d9e17f072 chore: moving github docs to github folder 2022-08-15 23:07:05 +00:00
Allan Bowe
421513850c chore: updating docs for ignoreList 2022-08-15 23:04:33 +00:00
10 changed files with 78 additions and 20 deletions

8
.gitpod.yml Normal file
View File

@@ -0,0 +1,8 @@
# This configuration file was automatically generated by Gitpod.
# Please adjust to your needs (see https://www.gitpod.io/docs/config-gitpod-file)
# and commit this file to your remote git repository to share the goodness with others.
tasks:
- init: npm install && npm run build

View File

@@ -23,18 +23,43 @@ Configuration is via a `.sasjslint` file with the following structure (these are
"hasDoxygenHeader": true,
"hasMacroNameInMend": true,
"hasMacroParentheses": true,
"ignoreList": [
"sajsbuild/",
"sasjsresults/"
],
"indentationMultiple": 2,
"lowerCaseFileNames": true,
"maxLineLength": 80,
"noNestedMacros": true,
"noSpacesInFileNames": true,
"noTabIndentation": true,
"noTrailingSpaces": true
"noTrailingSpaces": true,
"defaultHeader": "/**{lineEnding} @file{lineEnding} @brief <Your brief here>{lineEnding} <h4> SAS Macros </h4>{lineEnding}**/"
}
```
### SAS Lint Settings
#### defaultHeader
This sets the default program header - applies when a SAS program does NOT begin with `/**`. The default header is as follows:
```sas
/**
@file
@brief <Your brief here>
<h4> SAS Macros </h4>
**/
```
The default header is automatically applied when running `sasjs lint fix` in the SASjs CLI, or by hitting "save" when using the SASjs VS Code extension. If creating a new value, use `{lineEnding}` instead of `\n`, eg as follows:
```json
{
"defaultHeader": "/**{lineEnding} @file{lineEnding} @brief Our Company Brief{lineEnding}**/"
}
```
#### noEncodedPasswords
This will highlight any rows that contain a `{sas00X}` type password, or `{sasenc}`. These passwords (especially 001 and 002) are NOT secure, and should NEVER be pushed to source control or saved to the filesystem without special permissions applied.
@@ -60,6 +85,9 @@ As per the example [here](https://github.com/sasjs/lint/issues/20), macros defin
* Default: true
* Severity: WARNING
#### ignoreList
There may be specific files (or folders) that are not good candidates for linting. Simply list them in this array and they will be ignored. In addition, any files in the project `.gitignore` file will also be ignored.
#### indentationMultiple
This will check each line to ensure that the count of leading spaces can be divided cleanly by this multiple.

View File

@@ -7,6 +7,7 @@
"default": {
"noEncodedPasswords": true,
"hasDoxygenHeader": true,
"defaultHeader": "/**{lineEnding} @file{lineEnding} @brief <Your brief here>{lineEnding} <h4> SAS Macros </h4>{lineEnding}**/",
"hasMacroNameInMend": false,
"hasMacroParentheses": true,
"indentationMultiple": 2,
@@ -17,7 +18,8 @@
"noTabIndentation": true,
"noTrailingSpaces": true,
"lineEndings": "lf",
"strictMacroDefinition": true
"strictMacroDefinition": true,
"ignoreList": ["sajsbuild", "sasjsresults"]
},
"examples": [
{
@@ -33,7 +35,8 @@
"noNestedMacros": true,
"hasMacroParentheses": true,
"lineEndings": "crlf",
"strictMacroDefinition": true
"strictMacroDefinition": true,
"ignoreList": ["sajsbuild", "sasjsresults"]
}
],
"properties": {
@@ -53,6 +56,14 @@
"default": true,
"examples": [true, false]
},
"defaultHeader": {
"$id": "#/properties/defaultHeader",
"type": "boolean",
"title": "defaultHeader",
"description": "This sets the default program header - applies when a SAS program does NOT begin with `/**`.",
"default": "/**{lineEnding} @file{lineEnding} @brief <Your brief here>{lineEnding} <h4> SAS Macros </h4>{lineEnding}**/",
"examples": []
},
"hasMacroNameInMend": {
"$id": "#/properties/hasMacroNameInMend",
"type": "boolean",
@@ -143,11 +154,11 @@
},
"ignoreList": {
"$id": "#/properties/ignoreList",
"type": "object",
"type": "array",
"title": "ignoreList",
"description": "An array of paths or path patterns to ignore matching resources from linting. Files or folders matching patterns in .gitignore will always be ignored.",
"description": "An array of paths or path patterns to ignore when linting. Any files or matching patterns in the .gitignore file will also be ignored.",
"default": ["sasjsbuild/", "sasjsresults/"],
"examples": ["sasjs/services", "appinit.sas"]
"examples": ["sasjs/tests", "tmp/scratch.sas"]
}
}
}

View File

@@ -1,7 +1,8 @@
import { LintConfig } from '../types'
import { getLintConfig } from '../utils'
import { processText } from './shared'
export const formatText = async (text: string) => {
const config = await getLintConfig()
export const formatText = async (text: string, configuration?: LintConfig) => {
const config = configuration || (await getLintConfig())
return processText(text, config)
}

View File

@@ -19,7 +19,7 @@ const processContent = (config: LintConfig, content: string): string => {
config.fileLintRules
.filter((r) => !!r.fix)
.forEach((rule) => {
processedContent = rule.fix!(processedContent)
processedContent = rule.fix!(processedContent, config)
})
return processedContent
@@ -30,7 +30,7 @@ export const processLine = (config: LintConfig, line: string): string => {
config.lineLintRules
.filter((r) => !!r.fix)
.forEach((rule) => {
processedLine = rule.fix!(line)
processedLine = rule.fix!(line, config)
})
return processedLine

View File

@@ -3,8 +3,7 @@ import { LineEndings } from '../../types/LineEndings'
import { FileLintRule } from '../../types/LintRule'
import { LintRuleType } from '../../types/LintRuleType'
import { Severity } from '../../types/Severity'
const DoxygenHeader = `/**{lineEnding} @file{lineEnding} @brief <Your brief here>{lineEnding} <h4> SAS Macros </h4>{lineEnding}**/`
import { DefaultLintConfiguration } from '../../utils/getLintConfig'
const name = 'hasDoxygenHeader'
const description =
@@ -61,10 +60,11 @@ const fix = (value: string, config?: LintConfig): string => {
} else if (result[0].message == messageForSingleAsterisk)
return value.replace('/*', '/**')
config = config || new LintConfig(DefaultLintConfiguration)
const lineEndingConfig = config?.lineEndings || LineEndings.LF
const lineEnding = lineEndingConfig === LineEndings.LF ? '\n' : '\r\n'
return `${DoxygenHeader.replace(
return `${config?.defaultHeader.replace(
/{lineEnding}/g,
lineEnding
)}${lineEnding}${value}`

View File

@@ -16,6 +16,7 @@ import {
import { lowerCaseFileNames, noSpacesInFileNames } from '../rules/path'
import { LineEndings } from './LineEndings'
import { FileLintRule, LineLintRule, PathLintRule } from './LintRule'
import { getDefaultHeader } from '../utils'
/**
* LintConfig is the logical representation of the .sasjslint file.
@@ -32,6 +33,7 @@ export class LintConfig {
readonly maxLineLength: number = 80
readonly indentationMultiple: number = 2
readonly lineEndings: LineEndings = LineEndings.LF
readonly defaultHeader: string = getDefaultHeader()
constructor(json?: any) {
if (json?.ignoreList) {
@@ -87,6 +89,10 @@ export class LintConfig {
this.fileLintRules.push(hasDoxygenHeader)
}
if (json?.defaultHeader) {
this.defaultHeader = json.defaultHeader
}
if (json?.noSpacesInFileNames) {
this.pathLintRules.push(noSpacesInFileNames)
}

View File

@@ -3,6 +3,9 @@ import { LintConfig } from '../types/LintConfig'
import { readFile } from '@sasjs/utils/file'
import { getProjectRoot } from './getProjectRoot'
export const getDefaultHeader = () =>
`/**{lineEnding} @file{lineEnding} @brief <Your brief here>{lineEnding} <h4> SAS Macros </h4>{lineEnding}**/`
/**
* Default configuration that is used when a .sasjslint file is not found
*/
@@ -18,7 +21,8 @@ export const DefaultLintConfiguration = {
hasMacroNameInMend: true,
noNestedMacros: true,
hasMacroParentheses: true,
strictMacroDefinition: true
strictMacroDefinition: true,
defaultHeader: getDefaultHeader()
}
/**