-
Notifications
You must be signed in to change notification settings - Fork 86
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
ci: add require formly documentation rule #1019
Merged
Merged
Changes from 4 commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
af10662
ci: add require formly documentation rule
MaxKless 58630a1
fix: add missing docs
MaxKless 26b4255
fix: disable rule in testing module
MaxKless b1de945
fix: add docs to all formly components
MaxKless e98b0f5
fix: undefined in getCommentsBefore
MaxKless File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 || | ||
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
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
getCommentsBefore cannot be called with a falsy object. node.decorators?.[0] could be undefined.