mirror of
https://github.com/sasjs/lint.git
synced 2025-12-10 17:34:36 +00:00
Compare commits
11 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
a1ebb51230 | ||
| 496e0bc8fc | |||
|
|
f8b15c7d4d | ||
|
|
74e8df2a7b | ||
|
|
12e4eeb287 | ||
| bc7a7a7645 | |||
|
|
40e90995f8 | ||
|
|
80d0b39637 | ||
| c3a466f485 | |||
| 38656e9e89 | |||
| 386d0f5ff3 |
61
README.md
61
README.md
@@ -25,6 +25,7 @@ Configuration is via a `.sasjslint` file with the following structure (these are
|
|||||||
"hasMacroParentheses": true,
|
"hasMacroParentheses": true,
|
||||||
"ignoreList": ["sajsbuild/", "sasjsresults/"],
|
"ignoreList": ["sajsbuild/", "sasjsresults/"],
|
||||||
"indentationMultiple": 2,
|
"indentationMultiple": 2,
|
||||||
|
"lineEndings": "off",
|
||||||
"lowerCaseFileNames": true,
|
"lowerCaseFileNames": true,
|
||||||
"maxDataLineLength": 80,
|
"maxDataLineLength": 80,
|
||||||
"maxHeaderLineLength": 80,
|
"maxHeaderLineLength": 80,
|
||||||
@@ -50,14 +51,14 @@ For more details, and the default state, see the description of each rule below.
|
|||||||
|
|
||||||
### allowedGremlins
|
### allowedGremlins
|
||||||
|
|
||||||
An array of hex codes that represents allowed gremlins (invisible / undesirable characters). To allow all gremlins, you can also set the `noGremlins` rule to `false`.
|
An array of hex codes that represents allowed gremlins (invisible / undesirable characters). To allow all gremlins, you can also set the `noGremlins` rule to `false`.
|
||||||
|
|
||||||
Example:
|
Example:
|
||||||
|
|
||||||
```json
|
```json
|
||||||
{
|
{
|
||||||
"noGremlins": true,
|
"noGremlins": true,
|
||||||
"allowedGremlins": ["0x0080", "0x3000"]
|
"allowedGremlins": ["0x0080", "0x3000"]
|
||||||
}
|
}
|
||||||
```
|
```
|
||||||
|
|
||||||
@@ -122,6 +123,21 @@ This will check each line to ensure that the count of leading spaces can be divi
|
|||||||
- Default: 2
|
- Default: 2
|
||||||
- Severity: WARNING
|
- Severity: WARNING
|
||||||
|
|
||||||
|
### lineEndings
|
||||||
|
|
||||||
|
This setting ensures the line endings in a file to conform the configured type. Possible values are `lf`, `crlf` and `off` (off means rule is set to be off). If the value is missing, null or undefined then the check would also be switched off (no default applied).
|
||||||
|
|
||||||
|
- Default: "off"
|
||||||
|
- Severity: WARNING
|
||||||
|
|
||||||
|
Example (to enforce unix line endings):
|
||||||
|
|
||||||
|
```json
|
||||||
|
{
|
||||||
|
"lineEndings": "lf"
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
### lowerCaseFileNames
|
### lowerCaseFileNames
|
||||||
|
|
||||||
On *nix systems, it is imperative that autocall macros are in lowercase. When sharing code between windows and *nix systems, the difference in case sensitivity can also be a cause of lost developer time. For this reason, we recommend that sas filenames are always lowercase.
|
On *nix systems, it is imperative that autocall macros are in lowercase. When sharing code between windows and *nix systems, the difference in case sensitivity can also be a cause of lost developer time. For this reason, we recommend that sas filenames are always lowercase.
|
||||||
@@ -131,16 +147,16 @@ On *nix systems, it is imperative that autocall macros are in lowercase. When sh
|
|||||||
|
|
||||||
### maxDataLineLength
|
### maxDataLineLength
|
||||||
|
|
||||||
Datalines can be very wide, so to avoid the need to increase `maxLineLength` for the entire project, it is possible to raise the line length limit for the data records only. On a related note, as a developer, you should also be aware that code submitted in batch may have a default line length limit which is lower than you expect. See this [usage note](https://support.sas.com/kb/15/883.html) (and thanks to [sasutils for reminding us](https://github.com/sasjs/lint/issues/47#issuecomment-1064340104)).
|
Datalines can be very wide, so to avoid the need to increase `maxLineLength` for the entire project, it is possible to raise the line length limit for the data records only. On a related note, as a developer, you should also be aware that code submitted in batch may have a default line length limit which is lower than you expect. See this [usage note](https://support.sas.com/kb/15/883.html) (and thanks to [sasutils for reminding us](https://github.com/sasjs/lint/issues/47#issuecomment-1064340104)).
|
||||||
|
|
||||||
This feature will work for the following statements:
|
This feature will work for the following statements:
|
||||||
|
|
||||||
* cards
|
- cards
|
||||||
* cards4
|
- cards4
|
||||||
* datalines
|
- datalines
|
||||||
* datalines4
|
- datalines4
|
||||||
* parmcards
|
- parmcards
|
||||||
* parmcards4
|
- parmcards4
|
||||||
|
|
||||||
The `maxDataLineLength` setting is always the _higher_ of `maxDataLineLength` and `maxLineLength` (if you set a lower number, it is ignored).
|
The `maxDataLineLength` setting is always the _higher_ of `maxDataLineLength` and `maxLineLength` (if you set a lower number, it is ignored).
|
||||||
|
|
||||||
@@ -149,13 +165,13 @@ The `maxDataLineLength` setting is always the _higher_ of `maxDataLineLength` an
|
|||||||
|
|
||||||
See also:
|
See also:
|
||||||
|
|
||||||
* [hasDoxygenHeader](#hasdoxygenheader)
|
- [hasDoxygenHeader](#hasdoxygenheader)
|
||||||
* [maxHeaderLineLength](#maxheaderlinelength)
|
- [maxHeaderLineLength](#maxheaderlinelength)
|
||||||
* [maxLineLength](#maxlinelength)
|
- [maxLineLength](#maxlinelength)
|
||||||
|
|
||||||
### maxHeaderLineLength
|
### maxHeaderLineLength
|
||||||
|
|
||||||
In a program header it can be necessary to insert items such as URLs or markdown tables, that cannot be split over multiple lines. To avoid the need to increase `maxLineLength` for the entire project, it is possible to raise the line length limit for the header section only.
|
In a program header it can be necessary to insert items such as URLs or markdown tables, that cannot be split over multiple lines. To avoid the need to increase `maxLineLength` for the entire project, it is possible to raise the line length limit for the header section only.
|
||||||
|
|
||||||
The `maxHeaderLineLength` setting is always the _higher_ of `maxHeaderLineLength` and `maxLineLength` (if you set a lower number, it is ignored).
|
The `maxHeaderLineLength` setting is always the _higher_ of `maxHeaderLineLength` and `maxLineLength` (if you set a lower number, it is ignored).
|
||||||
|
|
||||||
@@ -164,9 +180,9 @@ The `maxHeaderLineLength` setting is always the _higher_ of `maxHeaderLineLength
|
|||||||
|
|
||||||
See also:
|
See also:
|
||||||
|
|
||||||
* [hasDoxygenHeader](#hasdoxygenheader)
|
- [hasDoxygenHeader](#hasdoxygenheader)
|
||||||
* [maxDataLineLength](#maxdatalinelength)
|
- [maxDataLineLength](#maxdatalinelength)
|
||||||
* [maxLineLength](#maxlinelength)
|
- [maxLineLength](#maxlinelength)
|
||||||
|
|
||||||
### maxLineLength
|
### maxLineLength
|
||||||
|
|
||||||
@@ -181,12 +197,12 @@ We strongly recommend a line length limit, and set the bar at 80. To turn this f
|
|||||||
|
|
||||||
See also:
|
See also:
|
||||||
|
|
||||||
* [maxDataLineLength](#maxdatalinelength)
|
- [maxDataLineLength](#maxdatalinelength)
|
||||||
* [maxHeaderLineLength](#maxheaderlinelength)
|
- [maxHeaderLineLength](#maxheaderlinelength)
|
||||||
|
|
||||||
### noGremlins
|
### noGremlins
|
||||||
|
|
||||||
Capture zero-width whitespace and other non-standard characters. The logic is borrowed from the [VSCode Gremlins Extension](https://github.com/nhoizey/vscode-gremlins) - if you are looking for more advanced gremlin zapping capabilities, we highly recommend to use their extension instead.
|
Capture zero-width whitespace and other non-standard characters. The logic is borrowed from the [VSCode Gremlins Extension](https://github.com/nhoizey/vscode-gremlins) - if you are looking for more advanced gremlin zapping capabilities, we highly recommend to use their extension instead.
|
||||||
|
|
||||||
The list of characters can be found in this file: [https://github.com/sasjs/lint/blob/main/src/utils/gremlinCharacters.ts](https://github.com/sasjs/lint/blob/main/src/utils/gremlinCharacters.ts)
|
The list of characters can be found in this file: [https://github.com/sasjs/lint/blob/main/src/utils/gremlinCharacters.ts](https://github.com/sasjs/lint/blob/main/src/utils/gremlinCharacters.ts)
|
||||||
|
|
||||||
@@ -247,11 +263,6 @@ This setting allows the default severity to be adjusted. This is helpful when ru
|
|||||||
- "warn" - show warning in the log (doesn’t affect exit code)
|
- "warn" - show warning in the log (doesn’t affect exit code)
|
||||||
- "error" - show error in the log (exit code is 1 when triggered)
|
- "error" - show error in the log (exit code is 1 when triggered)
|
||||||
|
|
||||||
## Upcoming Linting Rules:
|
|
||||||
|
|
||||||
- `noGremlins` -> identifies all invisible characters, other than spaces / tabs / line endings. If you really need that bell character, use a hex literal!
|
|
||||||
- `lineEndings` -> set a standard line ending, such as LF or CRLF
|
|
||||||
|
|
||||||
# SAS Formatter
|
# SAS Formatter
|
||||||
|
|
||||||
A formatter will automatically apply rules when you hit SAVE, which can save a LOT of time.
|
A formatter will automatically apply rules when you hit SAVE, which can save a LOT of time.
|
||||||
|
|||||||
@@ -20,7 +20,7 @@
|
|||||||
"noSpacesInFileNames": true,
|
"noSpacesInFileNames": true,
|
||||||
"noTabs": true,
|
"noTabs": true,
|
||||||
"noTrailingSpaces": true,
|
"noTrailingSpaces": true,
|
||||||
"lineEndings": "lf",
|
"lineEndings": "off",
|
||||||
"strictMacroDefinition": true,
|
"strictMacroDefinition": true,
|
||||||
"ignoreList": ["sajsbuild", "sasjsresults"]
|
"ignoreList": ["sajsbuild", "sasjsresults"]
|
||||||
},
|
},
|
||||||
@@ -182,9 +182,10 @@
|
|||||||
"lineEndings": {
|
"lineEndings": {
|
||||||
"$id": "#/properties/lineEndings",
|
"$id": "#/properties/lineEndings",
|
||||||
"type": "string",
|
"type": "string",
|
||||||
|
"enum": ["lf", "crlf", "off"],
|
||||||
"title": "lineEndings",
|
"title": "lineEndings",
|
||||||
"description": "Enforces the configured terminating character for each line. Shows a warning when incorrect line endings are present.",
|
"description": "Enforces the configured terminating character for each line. Shows a warning when incorrect line endings are present.",
|
||||||
"default": "lf",
|
"default": "off",
|
||||||
"examples": ["lf", "crlf"]
|
"examples": ["lf", "crlf"]
|
||||||
},
|
},
|
||||||
"strictMacroDefinition": {
|
"strictMacroDefinition": {
|
||||||
|
|||||||
@@ -1,4 +1,5 @@
|
|||||||
export enum LineEndings {
|
export enum LineEndings {
|
||||||
LF = 'lf',
|
LF = 'lf',
|
||||||
CRLF = 'crlf'
|
CRLF = 'crlf',
|
||||||
|
OFF = 'off'
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -168,7 +168,8 @@ describe('LintConfig', () => {
|
|||||||
hasMacroNameInMend: true,
|
hasMacroNameInMend: true,
|
||||||
noNestedMacros: true,
|
noNestedMacros: true,
|
||||||
hasMacroParentheses: true,
|
hasMacroParentheses: true,
|
||||||
noGremlins: true
|
noGremlins: true,
|
||||||
|
lineEndings: 'lf'
|
||||||
})
|
})
|
||||||
|
|
||||||
expect(config).toBeTruthy()
|
expect(config).toBeTruthy()
|
||||||
|
|||||||
@@ -82,8 +82,7 @@ export class LintConfig {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
this.fileLintRules.push(lineEndings)
|
if (json?.lineEndings && json.lineEndings !== LineEndings.OFF) {
|
||||||
if (json?.lineEndings) {
|
|
||||||
if (
|
if (
|
||||||
json.lineEndings !== LineEndings.LF &&
|
json.lineEndings !== LineEndings.LF &&
|
||||||
json.lineEndings !== LineEndings.CRLF
|
json.lineEndings !== LineEndings.CRLF
|
||||||
@@ -92,6 +91,7 @@ export class LintConfig {
|
|||||||
`Invalid value for lineEndings: can be ${LineEndings.LF} or ${LineEndings.CRLF}`
|
`Invalid value for lineEndings: can be ${LineEndings.LF} or ${LineEndings.CRLF}`
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
this.fileLintRules.push(lineEndings)
|
||||||
this.lineEndings = json.lineEndings
|
this.lineEndings = json.lineEndings
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -2,7 +2,7 @@ import * as fileModule from '@sasjs/utils/file'
|
|||||||
import { LintConfig } from '../types/LintConfig'
|
import { LintConfig } from '../types/LintConfig'
|
||||||
import { getLintConfig } from './getLintConfig'
|
import { getLintConfig } from './getLintConfig'
|
||||||
|
|
||||||
const expectedFileLintRulesCount = 6
|
const expectedFileLintRulesCount = 5
|
||||||
const expectedLineLintRulesCount = 6
|
const expectedLineLintRulesCount = 6
|
||||||
const expectedPathLintRulesCount = 2
|
const expectedPathLintRulesCount = 2
|
||||||
|
|
||||||
|
|||||||
@@ -2,6 +2,7 @@ import path from 'path'
|
|||||||
import { LintConfig } from '../types/LintConfig'
|
import { LintConfig } from '../types/LintConfig'
|
||||||
import { readFile } from '@sasjs/utils/file'
|
import { readFile } from '@sasjs/utils/file'
|
||||||
import { getProjectRoot } from './getProjectRoot'
|
import { getProjectRoot } from './getProjectRoot'
|
||||||
|
import { LineEndings } from '../types/LineEndings'
|
||||||
|
|
||||||
export const getDefaultHeader = () =>
|
export const getDefaultHeader = () =>
|
||||||
`/**{lineEnding} @file{lineEnding} @brief <Your brief here>{lineEnding} <h4> SAS Macros </h4>{lineEnding}**/`
|
`/**{lineEnding} @file{lineEnding} @brief <Your brief here>{lineEnding} <h4> SAS Macros </h4>{lineEnding}**/`
|
||||||
@@ -10,6 +11,7 @@ export const getDefaultHeader = () =>
|
|||||||
* Default configuration that is used when a .sasjslint file is not found
|
* Default configuration that is used when a .sasjslint file is not found
|
||||||
*/
|
*/
|
||||||
export const DefaultLintConfiguration = {
|
export const DefaultLintConfiguration = {
|
||||||
|
lineEndings: LineEndings.OFF,
|
||||||
noTrailingSpaces: true,
|
noTrailingSpaces: true,
|
||||||
noEncodedPasswords: true,
|
noEncodedPasswords: true,
|
||||||
hasDoxygenHeader: true,
|
hasDoxygenHeader: true,
|
||||||
|
|||||||
Reference in New Issue
Block a user