-
Notifications
You must be signed in to change notification settings - Fork 87
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
ci: add require-formly-code-documentation rule (#1019)
- Loading branch information
Showing
15 changed files
with
123 additions
and
4 deletions.
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
66 changes: 66 additions & 0 deletions
66
eslint-rules/src/rules/require-formly-code-documentation.ts
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,66 @@ | ||
import { AST_NODE_TYPES, TSESLint, TSESTree } from '@typescript-eslint/experimental-utils'; | ||
|
||
import { getClosestAncestorByKind } from '../helpers'; | ||
|
||
export const requireFormlyCodeDocumentationRule: TSESLint.RuleModule<string, []> = { | ||
meta: { | ||
messages: { | ||
missingDocumentationError: `Missing documentation for {{ artifactName }}. \n Please provide documentation for all Formly types, wrappers and extensions.`, | ||
}, | ||
type: 'problem', | ||
schema: [], | ||
}, | ||
create: context => { | ||
function hasPrecedingComment(node: TSESTree.ClassDeclaration) { | ||
return ( | ||
context.getSourceCode().getCommentsBefore(node)?.length > 0 || | ||
(node.decorators?.[0] && context.getSourceCode().getCommentsBefore(node.decorators[0])?.length > 0) | ||
); | ||
} | ||
if (!context.getFilename().includes('formly')) { | ||
return {}; | ||
} | ||
return { | ||
ClassDeclaration(node) { | ||
if (isFormlyArtifactClass(node) && !hasPrecedingComment(node)) { | ||
context.report({ | ||
node, | ||
messageId: 'missingDocumentationError', | ||
data: { | ||
artifactName: node.id.name, | ||
}, | ||
}); | ||
} | ||
}, | ||
'ExportNamedDeclaration Identifier'(node: TSESTree.Identifier) { | ||
if ( | ||
node.typeAnnotation?.typeAnnotation?.type === AST_NODE_TYPES.TSTypeReference && | ||
node.typeAnnotation.typeAnnotation.typeName.type === AST_NODE_TYPES.Identifier && | ||
node.typeAnnotation.typeAnnotation.typeName.name === 'FormlyExtension' && | ||
context | ||
.getSourceCode() | ||
.getCommentsBefore(getClosestAncestorByKind(context, AST_NODE_TYPES.ExportNamedDeclaration)).length === 0 | ||
) { | ||
context.report({ | ||
node, | ||
messageId: 'missingDocumentationError', | ||
data: { | ||
artifactName: node.name, | ||
}, | ||
}); | ||
} | ||
}, | ||
}; | ||
}, | ||
}; | ||
|
||
function isFormlyArtifactClass(node: TSESTree.ClassDeclaration): boolean { | ||
return ( | ||
['FieldType', 'FieldWrapper'].some( | ||
superClass => node.superClass?.type === AST_NODE_TYPES.Identifier && node.superClass?.name === superClass | ||
) || | ||
node.implements?.some( | ||
impl => impl.expression.type === AST_NODE_TYPES.Identifier && impl.expression.name === 'FormlyExtension' | ||
) | ||
); | ||
} |
14 changes: 14 additions & 0 deletions
14
eslint-rules/tests/require-formly-code-documentation.spec.ts
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,14 @@ | ||
import { requireFormlyCodeDocumentationRule } from '../src/rules/require-formly-code-documentation'; | ||
|
||
import { RuleTestConfig } from './_execute-tests'; | ||
|
||
const config: RuleTestConfig = { | ||
ruleName: 'require-formly-code-documentation', | ||
rule: requireFormlyCodeDocumentationRule, | ||
tests: { | ||
valid: [], | ||
invalid: [], | ||
}, | ||
}; | ||
|
||
export default config; |
3 changes: 3 additions & 0 deletions
3
...s/checkout-review/formly/checkout-review-tac-field/checkout-review-tac-field.component.ts
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
8 changes: 8 additions & 0 deletions
8
...pages/checkout-shipping/formly/shipping-radio-wrapper/shipping-radio-wrapper.component.ts
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
6 changes: 3 additions & 3 deletions
6
src/app/pages/registration/formly/disable-prefilled.extension.ts
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
3 changes: 3 additions & 0 deletions
3
src/app/pages/registration/formly/registration-tac-field/registration-tac-field.component.ts
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
1 change: 1 addition & 0 deletions
1
src/app/shared/formly/dev/testing/formly-testing-example/formly-testing-example.component.ts
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
1 change: 1 addition & 0 deletions
1
.../testing/formly-testing-fieldgroup-example/formly-testing-fieldgroup-example.component.ts
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
5 changes: 5 additions & 0 deletions
5
src/app/shared/formly/types/plain-text-field/plain-text-field.component.ts
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