diff --git a/.github/pull_request_template.md b/.github/pull_request_template.md new file mode 100644 index 0000000..36721cf --- /dev/null +++ b/.github/pull_request_template.md @@ -0,0 +1,15 @@ +# Pull Request Template + +## Description + + +## Checklist + + +- [ ] **Tests**: I have created multiple test case scenarios for my changes. +- [ ] **Passing Tests**: All existing and new tests are passing. +- [ ] **Version Bump**: I have increased the package version number in `package.json` following the [Semantic Versioning](https://semver.org/) (SEMVER) standard. +- [ ] **Focused Changes**: My code changes are focused solely on the matter described above. + +## Additional Information + diff --git a/.github/workflows/pullRequest.yml b/.github/workflows/pullRequest.yml index 31f87d3..48e5f26 100644 --- a/.github/workflows/pullRequest.yml +++ b/.github/workflows/pullRequest.yml @@ -9,6 +9,8 @@ jobs: steps: - name: Checkout uses: actions/checkout@v3 + with: + fetch-depth: 1 - name: Use Node.js 18.x uses: actions/setup-node@v3 @@ -39,6 +41,8 @@ jobs: steps: - name: Checkout uses: actions/checkout@v3 + with: + fetch-depth: 1 - name: Use Node.js 18.x uses: actions/setup-node@v3 @@ -70,6 +74,8 @@ jobs: steps: - name: Checkout uses: actions/checkout@v3 + with: + fetch-depth: 1 - name: Use Node.js 18.x uses: actions/setup-node@v3 @@ -95,6 +101,8 @@ jobs: steps: - name: Checkout uses: actions/checkout@v3 + with: + fetch-depth: 1 - name: Use Node.js 18.x uses: actions/setup-node@v3 @@ -112,3 +120,47 @@ jobs: - name: Find dead code run: yarn deadCode + + version-check: + name: Check package version + runs-on: ubuntu-latest + steps: + - name: Checkout PR + uses: actions/checkout@v3 + with: + fetch-depth: 1 + + - name: Checkout main + uses: actions/checkout@v3 + with: + ref: main + path: main + fetch-depth: 1 + + - name: Compare versions + id: version_check + run: | + PR_VERSION=$(node -p "require('./package.json').version") + MAIN_VERSION=$(node -p "require('./main/package.json').version") + if [ "$PR_VERSION" = "$MAIN_VERSION" ]; then + echo "ERROR_MESSAGE=Error: Package version has not been updated" >> $GITHUB_OUTPUT + exit 1 + elif ! npx semver -r ">$MAIN_VERSION" "$PR_VERSION" > /dev/null; then + echo "ERROR_MESSAGE=Error: New version ($PR_VERSION) is not greater than current version ($MAIN_VERSION)" >> $GITHUB_OUTPUT + exit 1 + else + echo "Package version has been updated correctly" + fi + + - name: Comment PR + if: failure() + uses: actions/github-script@v6 + with: + github-token: ${{secrets.GITHUB_TOKEN}} + script: | + github.rest.issues.createComment({ + issue_number: context.issue.number, + owner: context.repo.owner, + repo: context.repo.repo, + body: '${{ steps.version_check.outputs.ERROR_MESSAGE }}' + }) diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index 72ef5a1..16307e2 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -11,6 +11,8 @@ jobs: steps: - name: Checkout uses: actions/checkout@v3 + with: + fetch-depth: 1 - name: Use Node.js 16.x uses: actions/setup-node@v3 @@ -41,6 +43,8 @@ jobs: steps: - name: Checkout uses: actions/checkout@v3 + with: + fetch-depth: 1 - name: Use Node.js 16.x uses: actions/setup-node@v3 @@ -72,6 +76,8 @@ jobs: steps: - name: Checkout uses: actions/checkout@v3 + with: + fetch-depth: 1 - name: Use Node.js 16.x uses: actions/setup-node@v3 @@ -97,6 +103,8 @@ jobs: steps: - name: Checkout uses: actions/checkout@v3 + with: + fetch-depth: 1 - name: Use Node.js 16.x uses: actions/setup-node@v3 @@ -122,6 +130,8 @@ jobs: steps: - name: Checkout uses: actions/checkout@v3 + with: + fetch-depth: 1 - name: Use Node.js 16.x uses: actions/setup-node@v3 @@ -148,4 +158,3 @@ jobs: github_token: ${{ secrets.GITHUB_TOKEN }} publish_command: npm publish --access public generate_release_notes: true - diff --git a/__tests__/require-usememo.test.ts b/__tests__/require-usememo.test.ts index 1b0bc7b..6b27a02 100644 --- a/__tests__/require-usememo.test.ts +++ b/__tests__/require-usememo.test.ts @@ -327,6 +327,33 @@ describe('Rule - Require-usememo', () => { return {x, y}; }`, }, + // ignoredPropNames + { + code: `const Component = () => { + const myObject = {}; + return ; + }`, + options: [{ ignoredPropNames: ["ignoreProp"] }], + }, + { + code: `const Component = () => { + const myCallback = () => {}; + return ; + }`, + options: [{ ignoredPropNames: ["onClick"] }], + }, + { + code: `const Component = () => { + return
; + }`, + options: [{ ignoredPropNames: ["style"] }], + }, + { + code: `const Component = () => { + return ; + }`, + options: [{ ignoredPropNames: ["onClick"] }], + }, ], invalid: [ { diff --git a/docs/rules/require-usememo.md b/docs/rules/require-usememo.md index b23f075..2f36654 100644 --- a/docs/rules/require-usememo.md +++ b/docs/rules/require-usememo.md @@ -18,6 +18,7 @@ The rule takes an optional object: "fix": { "addImports": true }, "checkHookCalls": true, "ignoredHookCallsNames": { "useStateManagement": false }, + "ignoredPropNames": ["style"] }], } ``` @@ -42,6 +43,9 @@ You can use strict 1:1 comparisons (e.g., `"useCustomHook"`) or employ Minimatch - `fix`: Contains rules that only apply during eslint's fix routine. - `addImports`: Creates imports for useMemo and useCallback when one or both are added by this rule. Will increment to a existing import declaration or create a new one. Setting this to false disables it, defaults to true. + +- `ignoredPropNames`: This allows you to add specific prop name, thereby disabling them to be checked when used. + ## Autofix Examples (Function Components & Hooks only) To illustrate the autofix feature in action, below are some examples with input code and the corresponding fixed output: diff --git a/package.json b/package.json index 18cdfdb..1ce47dc 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "@arthurgeron/eslint-plugin-react-usememo", - "version": "2.4.1", + "version": "2.4.3", "description": "", "main": "dist/index.js", "author": "Stefano J. Attardi & Arthur Geron (node: T) { + + const ignoredPropNames = context.options?.[0]?.ignoredPropNames ?? []; + const { parent, value } = node as TSESTree.MethodDefinitionComputedName; if (value === null) return null; if (parent && !isComplexComponent(parent as TSESTree.JSXIdentifier)) return null; if ((value.type as string) === "JSXExpressionContainer") { + if (ignoredPropNames.includes((node as unknown as TSESTree.JSXAttribute).name?.name)) { + return null; + } process(node as TSESTree.MethodDefinitionComputedName, undefined, undefined, true); } return null;