mirror of
https://github.com/sasjs/lint.git
synced 2026-01-11 06:20:06 +00:00
chore(*): organise rules into folders by type
This commit is contained in:
2
src/rules/path/index.ts
Normal file
2
src/rules/path/index.ts
Normal file
@@ -0,0 +1,2 @@
|
||||
export { lowerCaseFileNames } from './lowerCaseFileNames'
|
||||
export { noSpacesInFileNames } from './noSpacesInFileNames'
|
||||
27
src/rules/path/lowerCaseFileNames.spec.ts
Normal file
27
src/rules/path/lowerCaseFileNames.spec.ts
Normal file
@@ -0,0 +1,27 @@
|
||||
import { Severity } from '../../types/Severity'
|
||||
import { lowerCaseFileNames } from './lowerCaseFileNames'
|
||||
|
||||
describe('lowerCaseFileNames', () => {
|
||||
it('should return an empty array when the file name has no uppercase characters', () => {
|
||||
const filePath = '/code/sas/my_sas_file.sas'
|
||||
expect(lowerCaseFileNames.test(filePath)).toEqual([])
|
||||
})
|
||||
|
||||
it('should return an empty array when the file name has no uppercase characters, even if the containing folder has uppercase characters', () => {
|
||||
const filePath = '/code/SAS Projects/my_sas_file.sas'
|
||||
expect(lowerCaseFileNames.test(filePath)).toEqual([])
|
||||
})
|
||||
|
||||
it('should return an array with a single diagnostic when the file name has uppercase characters', () => {
|
||||
const filePath = '/code/sas/my SAS file.sas'
|
||||
expect(lowerCaseFileNames.test(filePath)).toEqual([
|
||||
{
|
||||
message: 'File name contains uppercase characters',
|
||||
lineNumber: 1,
|
||||
startColumnNumber: 1,
|
||||
endColumnNumber: 1,
|
||||
severity: Severity.Warning
|
||||
}
|
||||
])
|
||||
})
|
||||
})
|
||||
32
src/rules/path/lowerCaseFileNames.ts
Normal file
32
src/rules/path/lowerCaseFileNames.ts
Normal file
@@ -0,0 +1,32 @@
|
||||
import { PathLintRule } from '../../types/LintRule'
|
||||
import { LintRuleType } from '../../types/LintRuleType'
|
||||
import { Severity } from '../../types/Severity'
|
||||
import path from 'path'
|
||||
|
||||
const name = 'lowerCaseFileNames'
|
||||
const description = 'Enforce the use of lower case file names.'
|
||||
const message = 'File name contains uppercase characters'
|
||||
const test = (value: string) => {
|
||||
const fileName = path.basename(value)
|
||||
if (fileName.toLocaleLowerCase() === fileName) return []
|
||||
return [
|
||||
{
|
||||
message,
|
||||
lineNumber: 1,
|
||||
startColumnNumber: 1,
|
||||
endColumnNumber: 1,
|
||||
severity: Severity.Warning
|
||||
}
|
||||
]
|
||||
}
|
||||
|
||||
/**
|
||||
* Lint rule that checks for the absence of uppercase characters in a given file name.
|
||||
*/
|
||||
export const lowerCaseFileNames: PathLintRule = {
|
||||
type: LintRuleType.Path,
|
||||
name,
|
||||
description,
|
||||
message,
|
||||
test
|
||||
}
|
||||
27
src/rules/path/noSpacesInFileNames.spec.ts
Normal file
27
src/rules/path/noSpacesInFileNames.spec.ts
Normal file
@@ -0,0 +1,27 @@
|
||||
import { Severity } from '../../types/Severity'
|
||||
import { noSpacesInFileNames } from './noSpacesInFileNames'
|
||||
|
||||
describe('noSpacesInFileNames', () => {
|
||||
it('should return an empty array when the file name has no spaces', () => {
|
||||
const filePath = '/code/sas/my_sas_file.sas'
|
||||
expect(noSpacesInFileNames.test(filePath)).toEqual([])
|
||||
})
|
||||
|
||||
it('should return an empty array when the file name has no spaces, even if the containing folder has spaces', () => {
|
||||
const filePath = '/code/sas projects/my_sas_file.sas'
|
||||
expect(noSpacesInFileNames.test(filePath)).toEqual([])
|
||||
})
|
||||
|
||||
it('should return an array with a single diagnostic when the file name has spaces', () => {
|
||||
const filePath = '/code/sas/my sas file.sas'
|
||||
expect(noSpacesInFileNames.test(filePath)).toEqual([
|
||||
{
|
||||
message: 'File name contains spaces',
|
||||
lineNumber: 1,
|
||||
startColumnNumber: 1,
|
||||
endColumnNumber: 1,
|
||||
severity: Severity.Warning
|
||||
}
|
||||
])
|
||||
})
|
||||
})
|
||||
34
src/rules/path/noSpacesInFileNames.ts
Normal file
34
src/rules/path/noSpacesInFileNames.ts
Normal file
@@ -0,0 +1,34 @@
|
||||
import { PathLintRule } from '../../types/LintRule'
|
||||
import { LintRuleType } from '../../types/LintRuleType'
|
||||
import { Severity } from '../../types/Severity'
|
||||
import path from 'path'
|
||||
|
||||
const name = 'noSpacesInFileNames'
|
||||
const description = 'Enforce the absence of spaces within file names.'
|
||||
const message = 'File name contains spaces'
|
||||
const test = (value: string) => {
|
||||
const fileName = path.basename(value)
|
||||
if (fileName.includes(' ')) {
|
||||
return [
|
||||
{
|
||||
message,
|
||||
lineNumber: 1,
|
||||
startColumnNumber: 1,
|
||||
endColumnNumber: 1,
|
||||
severity: Severity.Warning
|
||||
}
|
||||
]
|
||||
}
|
||||
return []
|
||||
}
|
||||
|
||||
/**
|
||||
* Lint rule that checks for the absence of spaces in a given file name.
|
||||
*/
|
||||
export const noSpacesInFileNames: PathLintRule = {
|
||||
type: LintRuleType.Path,
|
||||
name,
|
||||
description,
|
||||
message,
|
||||
test
|
||||
}
|
||||
Reference in New Issue
Block a user