-
-
Notifications
You must be signed in to change notification settings - Fork 33
feat: migrate package to TypeScript and publish types #534
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
Merged
Merged
Changes from 77 commits
Commits
Show all changes
82 commits
Select commit
Hold shift + click to select a range
2838607
change test-setup to ts
michaelfaith 8582fab
add build config
michaelfaith 046e58d
add types packages
michaelfaith d554cd3
rename files to ts
michaelfaith bc56d00
migrate fixer-return
michaelfaith 7e346f5
migrate consistent-output
michaelfaith 98cf8a3
migrate meta-property-ordering
michaelfaith ce6e93b
migrate no-deprecated-context-methods
michaelfaith baedd5b
migrate no-deprecated-report-api
michaelfaith 5cee9cd
migrate no-identical-tests
michaelfaith cb1d41d
migrate no-meta-replaced-by
michaelfaith 562fa66
migrate no-meta-schema-default
michaelfaith 9c5e68e
migrate no-missing-message-ids
michaelfaith 3694a1e
migrate no-missing-placeholders
michaelfaith 02314b4
migrate no-only-tests
michaelfaith d86155c
migrate no-property-in-node
michaelfaith 326cfce
migrate no-unused-message-ids
michaelfaith dbac215
migrate no-unused-placeholders
michaelfaith 912ab48
migrate no-useless-token-range
michaelfaith 16430e0
migrate prefer-message-ids
michaelfaith c3b8257
migrate prefer-object-rule
michaelfaith 6080c2a
migrate prefer-output-null
michaelfaith dbab18b
migrate prefer-placeholders
michaelfaith 4a187f5
migrate prefer-replace-text
michaelfaith 10b1135
migrate report-message-format
michaelfaith 80b563c
migrate require-meta-default-options
michaelfaith 900ae8c
migrate require-meta-docs-description
michaelfaith 0eb77cc
migrate prefer-replace-text
michaelfaith 11fdcbf
migrate require-meta-docs-recommended
michaelfaith 1ce2806
migrate require-meta-docs-url
michaelfaith ab52425
migrate require-meta-fixable
michaelfaith b797187
migrate require-meta-has-suggestions
michaelfaith 44c1bb4
migrate require-meta-schema-description
michaelfaith 7404dec
migrate require-meta-schema
michaelfaith db48780
migrate require-meta-type
michaelfaith 6f0cd12
migrate test-case-property-ordering
michaelfaith cf361fa
migrate test-case-shorthand-strings
michaelfaith 833e1d1
migrate plugin (index)
michaelfaith 0fe29c2
migrate indext.ts test
michaelfaith b1ea5c4
git mv all rule tests
michaelfaith 02e1d60
fix type issues in no-meta-replaced-by test
michaelfaith 6077cd4
fix type issues with no-missing-placeholders tests
michaelfaith c460aff
fix type issues with no-unused-placeholders tests
michaelfaith aa681ad
fix type issues with no-useless-token-range tests
michaelfaith be5b2bd
fix type issues with report-message-format tests
michaelfaith 96987fa
remove invalid case from valid array
michaelfaith 6035735
fix type issues with test-case-shorthand-strings
michaelfaith 9e11e48
fix type issues in rule-setup tests
michaelfaith 1c64770
Add explicit extensions to imports without them
michaelfaith 30a79ee
fix type issues in utils tests
michaelfaith 2b1d318
fix merge issue
michaelfaith ba1d108
adjust import order
michaelfaith 93dd0ac
fix plugin type
michaelfaith ac937db
fix utils tests
michaelfaith e97458e
switch to tsup for build
michaelfaith cb5eda9
Change import of `package.json` to require, for backwards compatibility
michaelfaith ff74f46
fix utils tests
michaelfaith 4bfc4b0
update rule-setup tests
michaelfaith 4da3c01
add build to publish workflow
michaelfaith 9a6060c
add slashes to .gitignore
michaelfaith 0259d01
remove jsdoc type annotation from `fixer-return`
michaelfaith 2559024
remove unnecessary param from `no-indentical-tests`
michaelfaith a3cf33a
add early return in `no-missing-placeholders`
michaelfaith 0052ccf
removed assert in `no-only-tests`
michaelfaith ead0948
remove empty param annotation from `no-property-in-node`
michaelfaith d91a0af
remove casting from no-unused-message-ids
michaelfaith 1ffacf7
add back valid test case to require-meta-type
michaelfaith ff19420
add explanatory comment to estree.d.ts
michaelfaith 64429ad
remove type annotation from comment in test-case-shorthand-string
michaelfaith 3768cfa
removed casting from no-meta-schema-default
michaelfaith 2f80268
remove casts from no-useless-token-range
michaelfaith 1abe593
remove cast from report-message-format
michaelfaith 22cf264
remove cast from require-meta-default-options
michaelfaith 88bc975
remove cast from require-meta-docs-url
michaelfaith 9f0af6f
remove casts from require-meta-fixables
michaelfaith fb85ff6
remove cast from require-meta-type
michaelfaith 1f22290
Adjust PartialRuleInfo types
michaelfaith 6890444
addressed feedback in utils
michaelfaith ce4f96f
ci: add typecheck step to CI workflow
michaelfaith 11fe179
removed unneeded ts-expect-error from eslint.config.ts
michaelfaith f287566
Address feedback in utils
michaelfaith 9eeef96
remove non-null assertion from require-meta-docs-recommended
michaelfaith 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 hidden or 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 hidden or 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 |
|---|---|---|
| @@ -1,10 +1,11 @@ | ||
| .idea | ||
| coverage | ||
| .idea/ | ||
| coverage/ | ||
| .vscode | ||
| node_modules/ | ||
| npm-debug.log | ||
| yarn.lock | ||
| .eslintcache | ||
| dist/ | ||
|
|
||
| # eslint-remote-tester | ||
| eslint-remote-tester-results |
This file contains hidden or 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 hidden or 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 hidden or 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 hidden or 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 |
|---|---|---|
|
|
@@ -2,21 +2,37 @@ | |
| * @fileoverview require fixer functions to return a fix | ||
| * @author 薛定谔的猫<[email protected]> | ||
| */ | ||
|
|
||
| import { getStaticValue } from '@eslint-community/eslint-utils'; | ||
| import type { Rule } from 'eslint'; | ||
| import type { | ||
| ArrowFunctionExpression, | ||
| FunctionExpression, | ||
| Identifier, | ||
| Node, | ||
| Position, | ||
| SourceLocation, | ||
| } from 'estree'; | ||
|
|
||
| import { | ||
| getContextIdentifiers, | ||
| isAutoFixerFunction, | ||
| isSuggestionFixerFunction, | ||
| } from '../utils.js'; | ||
| import type { FunctionInfo } from '../types.js'; | ||
|
|
||
| const DEFAULT_FUNC_INFO: FunctionInfo = { | ||
| upper: null, | ||
| codePath: null, | ||
| hasReturnWithFixer: false, | ||
| hasYieldWithFixer: false, | ||
| shouldCheck: false, | ||
| node: null, | ||
| }; | ||
|
|
||
| // ------------------------------------------------------------------------------ | ||
| // Rule Definition | ||
| // ------------------------------------------------------------------------------ | ||
|
|
||
| /** @type {import('eslint').Rule.RuleModule} */ | ||
| const rule = { | ||
| const rule: Rule.RuleModule = { | ||
| meta: { | ||
| type: 'problem', | ||
| docs: { | ||
|
|
@@ -25,36 +41,32 @@ const rule = { | |
| recommended: true, | ||
| url: 'https://github.com/eslint-community/eslint-plugin-eslint-plugin/tree/HEAD/docs/rules/fixer-return.md', | ||
| }, | ||
| fixable: null, | ||
| fixable: undefined, | ||
| schema: [], | ||
| messages: { | ||
| missingFix: 'Fixer function never returned a fix.', | ||
| }, | ||
| }, | ||
|
|
||
| create(context) { | ||
| let funcInfo = { | ||
| upper: null, | ||
| codePath: null, | ||
| hasReturnWithFixer: false, | ||
| hasYieldWithFixer: false, | ||
| shouldCheck: false, | ||
| node: null, | ||
| }; | ||
| let contextIdentifiers; | ||
| let funcInfo: FunctionInfo = DEFAULT_FUNC_INFO; | ||
| let contextIdentifiers = new Set<Identifier>(); | ||
|
|
||
| /** | ||
| * As we exit the fix() function, ensure we have returned or yielded a real fix by this point. | ||
| * If not, report the function as a violation. | ||
| * | ||
| * @param {ASTNode} node - A node to check. | ||
| * @param {Location} loc - Optional location to report violation on. | ||
| * @returns {void} | ||
| * @param node - A node to check. | ||
| * @param loc - Optional location to report violation on. | ||
| */ | ||
| function ensureFunctionReturnedFix( | ||
| node, | ||
| loc = (node.id || node).loc.start, | ||
| ) { | ||
| node: ArrowFunctionExpression | FunctionExpression, | ||
| loc: Position | SourceLocation | undefined = (node.type === | ||
| 'FunctionExpression' && node.id | ||
| ? node.id | ||
| : node | ||
| ).loc?.start, | ||
| ): void { | ||
| if ( | ||
| (node.generator && !funcInfo.hasYieldWithFixer) || // Generator function never yielded a fix | ||
| (!node.generator && !funcInfo.hasReturnWithFixer) // Non-generator function never returned a fix | ||
|
|
@@ -70,10 +82,9 @@ const rule = { | |
| /** | ||
| * Check if a returned/yielded node is likely to be a fix or not. | ||
| * A fix is an object created by fixer.replaceText() for example and returned by the fix function. | ||
| * @param {ASTNode} node - node to check | ||
| * @returns {boolean} | ||
| * @param node - node to check | ||
michaelfaith marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| */ | ||
| function isFix(node) { | ||
| function isFix(node: Node): boolean { | ||
| if (node.type === 'ArrayExpression' && node.elements.length === 0) { | ||
| // An empty array is not a fix. | ||
| return false; | ||
|
|
@@ -104,22 +115,22 @@ const rule = { | |
| }, | ||
|
|
||
| // Stacks this function's information. | ||
| onCodePathStart(codePath, node) { | ||
| onCodePathStart(codePath: Rule.CodePath, node: Node) { | ||
| funcInfo = { | ||
| upper: funcInfo, | ||
| codePath, | ||
| hasYieldWithFixer: false, | ||
| hasReturnWithFixer: false, | ||
| shouldCheck: | ||
| isAutoFixerFunction(node, contextIdentifiers) || | ||
| isSuggestionFixerFunction(node, contextIdentifiers), | ||
| isAutoFixerFunction(node, contextIdentifiers, context) || | ||
| isSuggestionFixerFunction(node, contextIdentifiers, context), | ||
| node, | ||
| }; | ||
| }, | ||
|
|
||
| // Pops this function's information. | ||
| onCodePathEnd() { | ||
| funcInfo = funcInfo.upper; | ||
| funcInfo = funcInfo.upper ?? DEFAULT_FUNC_INFO; | ||
| }, | ||
|
|
||
| // Yield in generators | ||
|
|
@@ -147,7 +158,7 @@ const rule = { | |
| 'ArrowFunctionExpression:exit'(node) { | ||
| if (funcInfo.shouldCheck) { | ||
| const sourceCode = context.sourceCode; | ||
| const loc = sourceCode.getTokenBefore(node.body).loc; // Show violation on arrow (=>). | ||
| const loc = sourceCode.getTokenBefore(node.body)?.loc; // Show violation on arrow (=>). | ||
| if (node.expression) { | ||
| // When the return is implied (no curly braces around the body), we have to check the single body node directly. | ||
| if (!isFix(node.body)) { | ||
|
|
||
Oops, something went wrong.
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.
I had issues with this which I fixed in qunitjs/eslint-plugin-qunit#584
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.
That doesn't really apply in this case, since this file's relative position to the package.json is the same in the dist folder as it is in the lib folder.
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.
Nice! Looks like I should be able to move index.js to fix that in my project: