-
Notifications
You must be signed in to change notification settings - Fork 17
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(specs): eslint with custom rules
- Loading branch information
Showing
10 changed files
with
288 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
import type { Config } from '@jest/types'; | ||
|
||
const config: Config.InitialOptions = { | ||
preset: 'ts-jest', | ||
testEnvironment: 'node', | ||
}; | ||
|
||
export default config; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
{ | ||
"name": "eslint-plugin-automation-custom", | ||
"version": "1.0.0", | ||
"description": "Custom rules for eslint", | ||
"packageManager": "yarn@3.1.1", | ||
"main": "dist/index.js", | ||
"files": [ | ||
"src/**.ts" | ||
], | ||
"scripts": { | ||
"build": "tsc", | ||
"test": "jest" | ||
}, | ||
"devDependencies": { | ||
"@types/jest": "27.4.1", | ||
"eslint": "8.11.0", | ||
"jest": "27.5.1", | ||
"ts-jest": "27.1.3", | ||
"ts-node": "10.7.0", | ||
"typescript": "4.5.4" | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
import { descriptionDot } from './rules/descriptionDot'; | ||
|
||
const rules = { | ||
'description-dot': descriptionDot, | ||
}; | ||
|
||
export { rules }; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
import type { Rule } from 'eslint'; | ||
import type { AST } from 'yaml-eslint-parser'; | ||
|
||
export const descriptionDot: Rule.RuleModule = { | ||
meta: { | ||
docs: { | ||
description: 'description must end with a dot', | ||
}, | ||
messages: { | ||
descriptionNoDot: 'description does not end with a dot', | ||
}, | ||
fixable: 'code', | ||
}, | ||
create(context) { | ||
if (!context.parserServices.isYAML) { | ||
return {}; | ||
} | ||
|
||
return { | ||
YAMLScalar(node): void { | ||
if (node.value !== 'description') { | ||
return; | ||
} | ||
const value: AST.YAMLScalar = node.parent.value; | ||
if (typeof value.value !== 'string' || value.value.endsWith('.')) { | ||
return; | ||
} | ||
context.report({ | ||
node, | ||
messageId: 'descriptionNoDot', | ||
fix(fixer) { | ||
return fixer.insertTextAfterRange(value.range, '.'); | ||
}, | ||
}); | ||
}, | ||
}; | ||
}, | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,73 @@ | ||
import { RuleTester } from 'eslint'; | ||
|
||
import { descriptionDot } from '../src/rules/descriptionDot'; | ||
|
||
const ruleTester = new RuleTester({ | ||
parser: require.resolve('yaml-eslint-parser'), | ||
}); | ||
|
||
ruleTester.run('description-dot', descriptionDot, { | ||
valid: [ | ||
` | ||
simple: | ||
type: number | ||
description: a number. | ||
`, | ||
` | ||
single: | ||
can: have | ||
description: simple. | ||
` /* | ||
` | ||
multi: | ||
description: > | ||
Multiline comment | ||
on description. | ||
`,*/, | ||
` | ||
multiStrip: | ||
description: >- | ||
Multiline comment | ||
on description. | ||
`, | ||
], | ||
invalid: [ | ||
{ | ||
code: ` | ||
simple: | ||
description: a number | ||
`, | ||
errors: [{ messageId: 'descriptionNoDot' }], | ||
output: ` | ||
simple: | ||
description: a number. | ||
`, | ||
}, | ||
{ | ||
code: ` | ||
single: | ||
description: simple | ||
`, | ||
errors: [{ messageId: 'descriptionNoDot' }], | ||
output: ` | ||
single: | ||
description: simple. | ||
`, | ||
} /* | ||
{ | ||
code: ` | ||
multi: | ||
description: > | ||
Multiline comment | ||
on description | ||
`, | ||
errors: [{ messageId: 'descriptionNoDot' }], | ||
output: ` | ||
multi: | ||
description: > | ||
Multiline comment | ||
on description. | ||
`, | ||
},*/, | ||
], | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
{ | ||
"extends": "../config/base.tsconfig.json", | ||
"compilerOptions": { | ||
"outDir": "dist", | ||
}, | ||
"include": [ | ||
"src/**/*.ts", | ||
], | ||
"exclude": [ | ||
"node_modules", | ||
"dist" | ||
] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters