File tree Expand file tree Collapse file tree 7 files changed +954
-1228
lines changed
Expand file tree Collapse file tree 7 files changed +954
-1228
lines changed Original file line number Diff line number Diff line change @@ -167,13 +167,13 @@ export async function execCLI<T extends CliArgs>(argv: T) {
167167 }
168168 } ;
169169 const formatLintingResult = ( result : any ) => {
170- return `allvarlighetsgrad : ${ colorizeSeverity ( result . allvarlighetsgrad ) } \nid: ${ result . id } \nkrav: ${
170+ return `\nallvarlighetsgrad : ${ colorizeSeverity ( result . allvarlighetsgrad ) } \nid: ${ result . id } \nkrav: ${
171171 result . krav
172172 } \nområde: ${ result . område } \nsökväg:[${ result . sökväg } ] \nomfattning:${ JSON . stringify (
173173 result . omfattning ,
174174 null ,
175175 2 ,
176- ) } `;
176+ ) } \ndesignregel: ${ result . helpUrl } `;
177177 } ;
178178 //Check specified option from yargs input
179179
Original file line number Diff line number Diff line change 1+ const RULES_DOC_REPO =
2+ 'https://github.com/diggsweden/rest-api-profil-lint-processor' ;
3+
4+
5+ /**
6+ * Constructs a helper Url together with correct Rule
7+ * @param ruleId ( Rule identifier)
8+ * @returns Normalized help url
9+ */
10+ export function buildRuleHelpUrl ( ruleId : string ) : string {
11+ const ref = process . env . RULES_DOC_REF || 'main' ;
12+ const normalizedId = ruleId
13+ . toLowerCase ( )
14+ . replace ( '.' , '' ) ;
15+
16+ return `${ RULES_DOC_REPO } /blob/${ ref } /GUIDELINES.md#id-${ normalizedId } ` ;
17+ }
Original file line number Diff line number Diff line change @@ -7,6 +7,7 @@ import { ISpectralDiagnostic } from '@stoplight/spectral-core';
77import spectralCore from '@stoplight/spectral-core' ;
88const { Spectral, Document } = spectralCore ;
99import { RapLPCustomSpectralDiagnostic } from './RapLPCustomSpectralDiagnostic.js' ;
10+ import { buildRuleHelpUrl } from '../rulesets/util/rules-doc.config.js' ;
1011
1112class RapLPCustomSpectral {
1213 private spectral : SpectralCore . Spectral ;
@@ -49,9 +50,12 @@ class RapLPCustomSpectral {
4950 if ( ruleClass && typeof ruleClass . getCustomProperties === 'function' ) {
5051 // Check for existance
5152 const customProperties = ruleClass . getCustomProperties ;
53+ const ruleId = ruleClass . customProperties . id ;
54+
5255 const customResult : RapLPCustomSpectralDiagnostic = {
53- id : ruleClass . customProperties . id ,
56+ id : ruleId ,
5457 område : ruleClass . customProperties . område ,
58+ helpUrl : ruleId ? buildRuleHelpUrl ( ruleId ) : undefined ,
5559 ...customProperties , // For more copy
5660 ...this . mapResultToCustom ( result ) ,
5761 } ;
Original file line number Diff line number Diff line change @@ -16,6 +16,9 @@ export interface RapLPCustomSpectralDiagnostic
1616 allvarlighetsgrad ?: string ;
1717 sökväg ?: any ;
1818 omfattning ?: any ;
19+
20+ /**Helper Url for guidelines */
21+ helpUrl ?: string ;
1922}
2023
2124
Original file line number Diff line number Diff line change 1+ // SPDX-FileCopyrightText: 2025 Digg - Agency for Digital Government
2+ //
3+ // SPDX-License-Identifier: EUPL-1.2
4+
5+ import { buildRuleHelpUrl } from '../../src/rulesets/util/rules-doc.config.js' ;
6+
7+ describe ( 'buildRuleHelpUrl' , ( ) => {
8+ const ORIGINAL_ENV = process . env ;
9+
10+ beforeEach ( ( ) => {
11+ process . env = { ...ORIGINAL_ENV } ;
12+ } ) ;
13+
14+ afterAll ( ( ) => {
15+ process . env = ORIGINAL_ENV ;
16+ } ) ;
17+
18+ it ( 'bygger korrekt GitHub-länk för regel-ID med punkt (SAK.16)' , ( ) => {
19+ process . env . RULES_DOC_REF = 'main' ;
20+
21+ const url = buildRuleHelpUrl ( 'SAK.16' ) ;
22+
23+ expect ( url ) . toBe (
24+ 'https://github.com/diggsweden/rest-api-profil-lint-processor/blob/main/GUIDELINES.md#id-sak16'
25+ ) ;
26+ } ) ;
27+
28+ it ( 'faller tillbaka till main om RULES_DOC_REF saknas' , ( ) => {
29+ delete process . env . RULES_DOC_REF ;
30+
31+ const url = buildRuleHelpUrl ( 'FOR.02' ) ;
32+
33+ expect ( url ) . toBe (
34+ 'https://github.com/diggsweden/rest-api-profil-lint-processor/blob/main/GUIDELINES.md#id-for02'
35+ ) ;
36+ } ) ;
37+
38+ it ( 'hanterar redan normaliserade ID:n korrekt' , ( ) => {
39+ process . env . RULES_DOC_REF = 'feature/test' ;
40+
41+ const url = buildRuleHelpUrl ( 'sak16' ) ;
42+
43+ expect ( url ) . toBe (
44+ 'https://github.com/diggsweden/rest-api-profil-lint-processor/blob/feature/test/GUIDELINES.md#id-sak16'
45+ ) ;
46+ } ) ;
47+ } ) ;
Original file line number Diff line number Diff line change 11{
22 "compilerOptions" : {
3- "types" : [" node" ],
43 "module" : " NodeNext" ,
54 "moduleResolution" : " NodeNext" ,
65 "target" : " ES2020" ,
You can’t perform that action at this time.
0 commit comments