feat: add disallow-references rule#6
Merged
StyleShit merged 13 commits intoStyleShit:mainfrom Apr 29, 2025
Merged
Conversation
StyleShit
requested changes
Apr 27, 2025
no-references ruledisallow-references rule
StyleShit
requested changes
Apr 27, 2025
README.md
Outdated
| | `php/eqeqeq` | Require the use of `===` and `!==` | | | | ||
| | `php/no-array-keyword` | Disallow the use of the array keyword | 🔧 | | | ||
| | `php/require-visibility` | Require visibility for class methods and properties | | 💡 | | ||
| | `php/disallow-references` | Disallow assigning by reference | | 💡 | |
src/index.ts
Outdated
|
|
||
| import { eqeqeq } from './rules/eqeqeq'; | ||
| import { noArrayKeyword } from './rules/no-array-keyword'; | ||
| import { disallowReferences } from './rules/disallow-references'; |
src/rules/disallow-references.ts
Outdated
| ) { | ||
| context.report({ | ||
| node, | ||
| messageId: 'noAssignRef', |
Owner
There was a problem hiding this comment.
Suggested change
| messageId: 'noAssignRef', | |
| messageId: 'disallowReferences', |
src/rules/disallow-references.ts
Outdated
| messageId: 'noAssignRef', | ||
| suggest: [ | ||
| { | ||
| desc: 'Remove reference assignment', |
Owner
There was a problem hiding this comment.
use a message id instead, and change the text ("remove reference syntax"?)
Collaborator
Author
There was a problem hiding this comment.
"Remove the reference operator (&)."
src/rules/disallow-references.ts
Outdated
|
|
||
| return fixer.replaceText( | ||
| node, | ||
| nodeText.replace(/&/g, ''), |
Owner
There was a problem hiding this comment.
Suggested change
| nodeText.replace(/&/g, ''), | |
| nodeText.replace(/^&/, ''), |
just for safety
src/rules/disallow-references.ts
Outdated
Comment on lines
+12
to
+15
| description: 'Disallow assigning by reference', | ||
| }, | ||
| messages: { | ||
| noAssignRef: 'Assigning by reference is not allowed.', |
src/rules/disallow-references.ts
Outdated
|
|
||
| export const disallowReferences = createRule<MessageIds, Options>({ | ||
| meta: { | ||
| type: 'layout', |
Owner
There was a problem hiding this comment.
Suggested change
| type: 'layout', | |
| type: 'suggestion', |
(we need to fix others as well)
Comment on lines
+17
to
+21
| valid: [ | ||
| '<?php $a = [];', | ||
| '<?php function foo() {}', | ||
| '<?php function foo($var) {}', | ||
| ], |
Owner
There was a problem hiding this comment.
add all the valid variations of the invalid ones
| endColumn: 37, | ||
| suggestions: [ | ||
| { | ||
| desc: 'Remove the reference operator (&).', |
StyleShit
reviewed
Apr 27, 2025
README.md
Outdated
| | `php/eqeqeq` | Require the use of `===` and `!==` | | | | ||
| | `php/no-array-keyword` | Disallow the use of the array keyword | 🔧 | | | ||
| | `php/require-visibility` | Require visibility for class methods and properties | | 💡 | | ||
| | `php/disallow-references` | Disallow assigning by reference | | 💡 | |
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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Closes #11