Skip to content
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

feat(eslint): add regexp and vue rules #238

Merged
merged 2 commits into from
Mar 18, 2025
Merged

Conversation

mheob
Copy link
Owner

@mheob mheob commented Mar 18, 2025

Summary by CodeRabbit

  • New Features

    • Enhanced ESLint configuration now supports customizable regular expression rules and robust Vue.js linting tailored for Vue projects.
    • Improved file recognition includes Vue files and offers refined YAML key sorting for better consistency.
    • Adjusted abbreviation settings to allow common shorthand (e.g., "db", "idx", "utils") without false warnings.
  • Chores

    • Upgraded several dependencies and tooling for improved performance and compatibility.
    • Expanded the spell check dictionary with additional accepted terms.

Also update all dependencies.
@mheob mheob added dependencies Pull requests that update a dependency file enhancement New feature or request eslint Belongs to ESLint config labels Mar 18, 2025
Copy link

height bot commented Mar 18, 2025

Link Height tasks by mentioning a task ID in the pull request title or commit messages, or description and comments with the keyword link (e.g. "Link T-123").

💡Tip: You can also use "Close T-X" to automatically close a task when the pull request is merged.

Copy link

changeset-bot bot commented Mar 18, 2025

🦋 Changeset detected

Latest commit: d6371b4

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 1 package
Name Type
@mheob/eslint-config Minor

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

Copy link

vercel bot commented Mar 18, 2025

The latest updates on your projects. Learn more about Vercel for Git ↗︎

Name Status Preview Comments Updated (UTC)
eslint-config ✅ Ready (Inspect) Visit Preview 💬 Add feedback Mar 18, 2025 9:25am

Copy link

coderabbitai bot commented Mar 18, 2025

Walkthrough

This pull request updates the ESLint configuration for the @mheob/eslint-config package by introducing new configuration functions for regexp and Vue rules. It includes dependency updates in multiple package files, adds new type definitions and interfaces for rule options, and adjusts configuration logic such as sorting and unicorn rules. Additional changes include a changeset for a minor version bump, a couple of spell-check dictionary additions, and enhancements in the factory function to conditionally include Vue and regexp configurations based on package availability.

Changes

File(s) Change Summary
.changeset/violet-lemons-flash.md Introduced a changeset file with a minor version update for @mheob/eslint-config and details on adding regexp and vue ESLint rules.
.cspell.json Added new words ("nonwords", "rulelevels") to the spell checker dictionary.
package.json
packages/eslint-config/package.json
Updated dependency versions (e.g., lint-staged, various ESLint plugins, eslint-config-next) and package manager version; added new dependencies (eslint-plugin-regexp, eslint-plugin-vue, local-pkg).
packages/eslint-config/scripts/typegen.ts
packages/eslint-config/src/configs/index.ts
Added a new import for regexp and exported new configurations (disables, regexp, vue).
packages/eslint-config/src/configs/regexp.ts
packages/eslint-config/src/configs/vue.ts
Introduced new asynchronous configuration functions for regexp and Vue ESLint rules.
packages/eslint-config/src/configs/sort.ts Augmented the sortPnpmWorkspaceYaml function with a new rule to sort YAML keys in ascending order.
packages/eslint-config/src/configs/unicorn.ts Expanded allowed abbreviation replacements by adding entries for db, idx, and utils.
packages/eslint-config/src/factory.ts Enhanced the factory function by adding parameters and logic to conditionally include Vue and regexp configurations based on package existence and provided options.
packages/eslint-config/src/globs.ts Added a new constant GLOB_VUE and updated the source file glob list to include Vue files.
packages/eslint-config/src/typegen.d.ts
packages/eslint-config/src/types.ts
Introduced multiple new type definitions and updated interfaces to support regexp and Vue rule options.

Sequence Diagram(s)

sequenceDiagram
    participant C as Caller
    participant F as mheob()
    participant P as isPackageExists()
    participant V as Vue Config (vue)
    participant R as Regexp Config (regexp)

    C->>F: Call mheob(options)
    F->>P: Check for Vue package presence
    P-->>F: Return enableVue status
    alt enableVue is true
        F->>V: Invoke vue() with sub-options
        V-->>F: Return Vue configuration object
    end
    alt enableRegexp is true
        F->>R: Invoke regexp() with options
        R-->>F: Return regexp configuration object
    end
    F->>C: Return consolidated ESLint configurations
Loading

Possibly related PRs

Warning

There were issues while running some tools. Please review the errors and either fix the tool’s configuration or disable the tool if it’s a critical failure.

🔧 ESLint

If the error stems from missing dependencies, add them to the package.json file. For unrecoverable errors (e.g., due to private dependencies), disable the tool in the CodeRabbit configuration.

Scope: all 2 workspace projects
Progress: resolved 0, reused 0, downloaded 1, added 0
Progress: resolved 55, reused 0, downloaded 54, added 0
/tmp/eslint/packages/eslint-config:
 ERR_PNPM_WORKSPACE_PKG_NOT_FOUND  In packages/eslint-config: "@mheob/tsconfig@workspace:*" is in the dependencies but no package named "@mheob/tsconfig" is present in the workspace

This error happened while installing a direct dependency of /tmp/eslint/packages/eslint-config

Packages found in the workspace:

Tip

⚡🧪 Multi-step agentic review comment chat (experimental)
  • We're introducing multi-step agentic chat in review comments. This experimental feature enhances review discussions with the CodeRabbit agentic chat by enabling advanced interactions, including the ability to create pull requests directly from comments.
    - To enable this feature, set early_access to true under in the settings.
✨ Finishing Touches
  • 📝 Generate Docstrings

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share
🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Generate unit testing code for this file.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai generate unit testing code for this file.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read src/utils.ts and generate unit testing code.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (Invoked using PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai generate docstrings to generate docstrings for this PR.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

Copy link

Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 1

🧹 Nitpick comments (5)
packages/eslint-config/src/configs/regexp.ts (2)

16-20: Extend logic for array-based rule severity
Right now, only string 'error' rules get converted to 'warn'. If a rule is configured like ['error', {...}], it won't be updated. Consider expanding the condition to handle array-based severity levels.

 if (options.level === 'warn') {
   for (const key in rules) {
-    if (rules[key] === 'error') rules[key] = 'warn';
+    const current = rules[key];
+    if (Array.isArray(current)) {
+      if (current[0] === 'error') {
+        current[0] = 'warn';
+      }
+    } else if (current === 'error') {
+      rules[key] = 'warn';
+    }
   }
 }

22-31: Add usage example or mention test coverage
Consider adding usage examples or tests for this new configuration to ensure that the returned config remains correct as your code evolves.

packages/eslint-config/src/types.ts (1)

59-64: Fix documentation grammar
The JSDoc comment says "Override rulelevels". For clarity, replace it with "Override rule levels".

  /**
-  * Override rulelevels
+  * Override rule levels
   */
  level?: 'error' | 'warn';
packages/eslint-config/package.json (1)

69-69: Consider adding Vue and Svelte peer dependencies

While you've added the Vue and Svelte dependencies and updated their parsers, you might want to consider adding them to the peerDependenciesMeta section with optional: true, similar to how you've handled other framework-specific dependencies. This would clarify that they're optional dependencies for users.

Also applies to: 71-71

packages/eslint-config/src/typegen.d.ts (1)

3152-3159: Duplicate comment descriptions for nested components.

The same comment description is used for both no-nested-component-definitions and no-nested-components. Consider documenting the specific differences between these rules if they exist.

📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 27e81e5 and d6371b4.

⛔ Files ignored due to path filters (1)
  • pnpm-lock.yaml is excluded by !**/pnpm-lock.yaml
📒 Files selected for processing (14)
  • .changeset/violet-lemons-flash.md (1 hunks)
  • .cspell.json (1 hunks)
  • package.json (1 hunks)
  • packages/eslint-config/package.json (2 hunks)
  • packages/eslint-config/scripts/typegen.ts (2 hunks)
  • packages/eslint-config/src/configs/index.ts (2 hunks)
  • packages/eslint-config/src/configs/regexp.ts (1 hunks)
  • packages/eslint-config/src/configs/sort.ts (1 hunks)
  • packages/eslint-config/src/configs/unicorn.ts (1 hunks)
  • packages/eslint-config/src/configs/vue.ts (1 hunks)
  • packages/eslint-config/src/factory.ts (7 hunks)
  • packages/eslint-config/src/globs.ts (2 hunks)
  • packages/eslint-config/src/typegen.d.ts (56 hunks)
  • packages/eslint-config/src/types.ts (3 hunks)
🧰 Additional context used
🧬 Code Definitions (5)
packages/eslint-config/scripts/typegen.ts (1)
packages/eslint-config/src/configs/regexp.ts (1) (1)
  • regexp (7:32)
packages/eslint-config/src/configs/regexp.ts (1)
packages/eslint-config/src/types.ts (3) (3)
  • OptionsOverrides (55:57)
  • OptionsRegExp (59:64)
  • TypedFlatConfigItem (14:23)
packages/eslint-config/src/configs/vue.ts (2)
packages/eslint-config/src/types.ts (4) (4)
  • OptionsFiles (25:28)
  • OptionsHasTypeScript (39:41)
  • OptionsOverrides (55:57)
  • TypedFlatConfigItem (14:23)
packages/eslint-config/src/globs.ts (1) (1)
  • GLOB_VUE (23:23)
packages/eslint-config/src/factory.ts (3)
packages/eslint-config/src/utils/package.ts (1) (1)
  • existsPackage (60:62)
packages/eslint-config/src/configs/regexp.ts (1) (1)
  • regexp (7:32)
packages/eslint-config/src/configs/vue.ts (1) (1)
  • vue (10:137)
packages/eslint-config/src/typegen.d.ts (1)
packages/eslint-config/src/types.ts (1) (1)
  • ConfigNames (8:8)
🪛 Biome (1.9.4)
packages/eslint-config/src/configs/vue.ts

[error] 69-69: Avoid the use of spread (...) syntax on accumulators.

Spread syntax should be avoided on accumulators (like those in .reduce) because it causes a time complexity of O(n^2).
Consider methods such as .splice or .push instead.

(lint/performance/noAccumulatingSpread)


[error] 72-72: Avoid the use of spread (...) syntax on accumulators.

Spread syntax should be avoided on accumulators (like those in .reduce) because it causes a time complexity of O(n^2).
Consider methods such as .splice or .push instead.

(lint/performance/noAccumulatingSpread)


[error] 75-75: Avoid the use of spread (...) syntax on accumulators.

Spread syntax should be avoided on accumulators (like those in .reduce) because it causes a time complexity of O(n^2).
Consider methods such as .splice or .push instead.

(lint/performance/noAccumulatingSpread)

🔇 Additional comments (30)
.cspell.json (1)

36-36: Appropriate dictionary additions for ESLint rule development

These new entries enhance the spell checker dictionary to recognize terms related to regexp rules and ESLint configuration levels, which aligns with the PR's objective of adding new rule configurations.

Also applies to: 41-41

.changeset/violet-lemons-flash.md (1)

1-5: Well-structured changeset for package version update

The changeset correctly identifies this as a minor version update, which is appropriate for adding new features (regexp and Vue rules) without breaking existing functionality. The description is concise and accurately captures the changes.

packages/eslint-config/src/configs/unicorn.ts (1)

31-31: Good additions to allowed abbreviations

Adding db, idx, and utils to the allowed abbreviations is sensible as these are widely understood terms in development contexts. This will prevent unnecessary warnings while maintaining the overall benefit of the prevent-abbreviations rule.

Also applies to: 35-35, 40-40

packages/eslint-config/scripts/typegen.ts (1)

18-18: Correctly integrates regexp configuration

The changes properly integrate the new regexp configuration into the type generation system. The import is added in the correct location, and the regexp() function is appropriately included in the combine function call, ensuring the regexp rules will be included in the generated types.

Also applies to: 48-48

package.json (2)

42-42: LGTM! Dependency version update.

The update to lint-staged from ^15.4.3 to ^15.5.0 is a minor version bump which should maintain backward compatibility.


48-48: LGTM! Package manager version update.

Updating pnpm from 10.6.1 to 10.6.4 is a patch version update that typically includes bug fixes.

packages/eslint-config/src/configs/index.ts (1)

4-4: LGTM! New module exports added.

The added exports for disables, regexp, and vue align with the PR objective of adding support for regexp and Vue rules.

Also applies to: 15-15, 22-22

packages/eslint-config/src/configs/sort.ts (1)

165-168: LGTM! Enhanced YAML sorting capability.

Adding a catch-all pattern '.*' ensures that all keys in YAML files are sorted in ascending order, improving consistency across the codebase.

packages/eslint-config/src/globs.ts (2)

23-23: LGTM! Added Vue file pattern.

The addition of a dedicated glob pattern for Vue files is essential for the Vue rules implementation.


47-47: LGTM! Included Vue files in sources.

Adding the Vue glob pattern to GLOB_ALL_SRC ensures that Vue files will be properly processed by the ESLint configuration.

packages/eslint-config/src/configs/regexp.ts (1)

1-2: Confirm necessity of @ts-nocheck
The file is ignoring TS checks; confirm if it's required or if we can enable type-checking for better reliability and catch potential issues earlier.

packages/eslint-config/src/types.ts (2)

178-185: Verify default behavior for RegExp rules
The doc states @default true, so confirm that your configuration code applies a true default if regexp is omitted. Otherwise, the eventual config might not load the plugin as intended.


239-245: Confirm design for Vue integration
The new vue property follows the precedent of other booleans for optional features. Verify that any auto-detection or fallback logic aligns with user needs—for example, turning on Vue rules only if Vue is actually installed.

packages/eslint-config/src/factory.ts (6)

6-6: Good addition of isPackageExists from local-pkg

Using isPackageExists function from local-pkg is a better approach than the existing existsPackage from your utils. It provides more reliable package detection which is important for the Vue auto-detection feature.


12-12: LGTM - Necessary imports for new functionality

Correctly importing the new configuration functions (disables, regexp, and vue) to support the expanded ESLint ruleset. The disables function was already used on line 246 but wasn't explicitly imported before.

Also applies to: 23-23, 32-32


51-51: Good approach for Vue package detection

Defining a constant with all common Vue-related packages makes the auto-detection feature more robust and maintainable.


152-152: Well-designed default configuration flags

The default values are well thought out:

  • regexp: enableRegexp = true: Enabling regexp rules by default is sensible as they're broadly applicable
  • vue: enableVue = VuePackages.some(i => isPackageExists(i)): Auto-detecting Vue makes the config more user-friendly

This approach provides good defaults while still allowing users to override them.

Also applies to: 156-156


193-195: Good implementation of regexp configuration

The configuration properly handles both boolean and object options for the regexp plugin, allowing users to either simply enable/disable or provide detailed configuration.


206-215: Well-structured Vue integration

The Vue integration is comprehensive:

  1. Adds .vue file extension to component extensions
  2. Correctly passes TypeScript configuration
  3. Handles sub-options and overrides appropriately

This implementation ensures Vue files will be properly linted with the appropriate parser and rule set.

packages/eslint-config/package.json (3)

38-40: Good dependency maintenance - minor version updates

Keeping dependencies up-to-date with minor version updates is a good practice for bug fixes and security improvements. These updates seem well-coordinated and don't include any major version jumps that might introduce breaking changes.

Also applies to: 42-42, 49-50, 55-55


57-57: Appropriate new dependencies for feature additions

The newly added dependencies align perfectly with the functionality additions in the codebase:

  • eslint-plugin-regexp (2.7.0) - For the new regexp rules
  • eslint-plugin-vue (10.0.0) - For Vue.js linting support
  • local-pkg (1.1.1) - For package detection used in Vue auto-detection

These are all at stable versions and are necessary for the new features.

Also applies to: 61-61, 65-65


76-76: Development dependencies properly updated

The updated development dependencies ensure compatibility with the main dependencies and provide the latest features for the development workflow.

Also applies to: 85-86, 90-90

packages/eslint-config/src/typegen.d.ts (8)

640-867: Documentation links updated to the latest version.

All import plugin documentation URLs have been updated from their previous version to v4.8.0, ensuring links point to the current documentation.


2815-2819: Added React DOM modernization rules.

Added new React DOM rules that help migrate from legacy APIs to modern ones:

  • react-dom/no-hydrate: Replaces ReactDom.hydrate() with hydrateRoot()
  • react-dom/no-render: Replaces ReactDom.render() with createRoot(node).render()
  • react-dom/no-use-form-state: Adds checks for form state usage

Also applies to: 2835-2839, 2865-2869


3231-3235: Added forward ref validation rule.

Added rule to enforce that a ref parameter is set when using forwardRef which aligns with React best practices.


3271-3680: Added comprehensive support for RegExp rules.

Added extensive rule definitions from eslint-plugin-regexp, covering:

  • Pattern validation and optimization
  • Best practices for regular expressions
  • Performance considerations (backtracking, linear vs. super-linear behavior)
  • Style and readability improvements

This is a significant enhancement that will help catch common regex issues and improve regex quality across the codebase.


4024-4028: Added Svelte-specific rules.

Added two new Svelte rules:

  • svelte/no-unnecessary-state-wrap: Prevents unnecessary $state wrapping
  • svelte/no-unused-props: Helps identify unused props in components

These additions will help maintain cleaner Svelte components.

Also applies to: 4034-4038


10652-10769: Added comprehensive type definitions for RegExp rules.

Added detailed TypeScript interfaces for all the RegExp rule options, providing proper type checking and documentation for each configuration option. This enables proper IDE autocomplete and validation when configuring these rules.


10998-11012: Added Svelte rule type definitions.

Added TypeScript interfaces for the new Svelte rules with appropriate configuration options:

  • SvelteNoUnnecessaryStateWrap: Controls reactive class detection and reassignment
  • SvelteNoUnusedProps: Configures prop usage checking with pattern exclusions

These provide proper type safety when configuring these rules.


12935-12935: Updated ConfigNames type to include the new RegExp rules.

The new RegExp rules configuration has been properly added to the ConfigNames type, ensuring type completeness for the configuration system.

@kodiakhq kodiakhq bot merged commit bfe4383 into main Mar 18, 2025
10 checks passed
@kodiakhq kodiakhq bot deleted the eslint-add-vue-and-regexp branch March 18, 2025 09:37
kodiakhq bot pushed a commit that referenced this pull request Mar 19, 2025
This PR was opened by the [Changesets release](https://github.com/changesets/action) GitHub action. When you're ready to do a release, you can merge this and the packages will be published to npm automatically. If you're not ready to do a release yet, that's fine, whenever you add more changesets to main, this PR will be updated.


# Releases
## @mheob/[email protected]

### Minor Changes

-   [#238](#238) ([@mheob](https://github.com/mheob)): add `regexp` and `vue` rules




## Summary by CodeRabbit

- **New Features**
	- Enhanced linting capabilities with added rules for regular expression and Vue file support.
- **Chores**
	- Updated the package version to 8.3.0.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
dependencies Pull requests that update a dependency file enhancement New feature or request eslint Belongs to ESLint config
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant