Skip to content

Migrate to eslint 9 #3

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 18 commits into from
Oct 4, 2024
Merged

Migrate to eslint 9 #3

merged 18 commits into from
Oct 4, 2024

Conversation

omermecitoglu
Copy link
Owner

@omermecitoglu omermecitoglu commented Jul 3, 2024

Summary by CodeRabbit

Release Notes

  • New Features

    • Introduced automated dependency updates through Dependabot for enhanced project maintenance.
    • Added comprehensive ESLint configurations for JavaScript, TypeScript, React, and accessibility checks.
    • Implemented TypeScript configuration for better compilation management.
    • Added support for managing unused imports and variables in ESLint.
  • Bug Fixes

    • Removed outdated linting configurations to streamline code quality enforcement.
  • Chores

    • Updated package.json to reflect major version changes and improved dependency management.
    • Enhanced .gitignore to exclude build artifacts, keeping the repository clean.
  • Documentation

    • Added tsconfig.json for TypeScript project settings.

@omermecitoglu omermecitoglu linked an issue Jul 3, 2024 that may be closed by this pull request
7 tasks
@omermecitoglu
Copy link
Owner Author

@coderabbitai review

Copy link

coderabbitai bot commented Sep 19, 2024

Actions performed

Review triggered.

Note: CodeRabbit is an incremental review system and does not re-review already reviewed commits. This command is applicable only when automatic reviews are paused.

Copy link

coderabbitai bot commented Sep 19, 2024

Walkthrough

The changes involve the removal and addition of several configuration files related to ESLint and TypeScript, along with updates to the project’s dependency management and build processes. Key modifications include the introduction of new ESLint configurations, the setup of Dependabot for automated dependency updates, and the restructuring of the package.json file to reflect a major version increment. Additionally, several files related to previous ESLint configurations have been deleted, and new TypeScript configurations have been added to enhance the project's maintainability.

Changes

File(s) Change Summary
.eslintrc, index.js, jsx.js Removed ESLint configuration files that defined various linting rules and standards.
.github/dependabot.yml Added configuration for Dependabot to check for dependency updates daily, with a specified user for management.
.github/workflows/release-package.yml Removed workflow for publishing packages to NPM.
.github/workflows/release.yml Added new workflow for automating the release process on pushes to the main branch.
.gitignore Added dist directory to the list of ignored files.
.npmrc Introduced configuration to prevent Git tags during npm versioning.
global.d.ts Added TypeScript declarations for eslint-plugin-react and eslint-plugin-import.
package.json Major version increment to 2.0.0, with updated author details, keywords, repository links, and an exports field specifying module entry points.
src/base.ts, src/import.ts, src/index.ts, src/jsx-a11y.ts, src/react.ts, src/stylistic.ts, src/typescript.ts, src/unused-imports.ts Added new ESLint configuration files tailored for various aspects of JavaScript and TypeScript projects, enforcing coding standards and best practices.
tsconfig.json Introduced TypeScript configuration file with various compiler options for managing TypeScript code.

Suggested reviewers

  • omermecitoglu

🐰 In the land of code, where changes bloom,
New rules and configs make room for the zoom.
With linting so bright, and types set just right,
Our project now dances, oh what a delight!
Dependabot's here, keeping packages near,
Hopping through updates, spreading good cheer! 🎉


Thank you for using CodeRabbit. We offer it for free to the OSS community and would appreciate your support in helping us grow. If you find it useful, would you consider giving us a shout-out on your favorite social media?

❤️ 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 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

@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

Outside diff range and nitpick comments (1)
src/import.ts (1)

1-1: Consider removing the commented-out lines if not needed.

The commented-out lines 1 and 6 suggest that the eslint-plugin-import plugin is not being used directly. If this is intentional and the lines are not needed, consider removing them to avoid confusion and improve code clarity.

Apply this diff to remove the commented-out lines:

-// import importPlugin from "eslint-plugin-import";
 
 export default [
   {
     plugins: {
-      // import: importPlugin,
     },
     rules: {
       "import/order": ["error", {

Also applies to: 6-6

Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

Commits

Files that changed from the base of the PR and between 1b2bc65 and 1a0d571.

Files ignored due to path filters (1)
  • package-lock.json is excluded by !**/package-lock.json
Files selected for processing (22)
  • .eslintrc (0 hunks)
  • .github/dependabot.yml (1 hunks)
  • .github/workflows/release-package.yml (1 hunks)
  • .gitignore (1 hunks)
  • .npmrc (1 hunks)
  • base.js (0 hunks)
  • eslint.config.js (1 hunks)
  • global.d.ts (1 hunks)
  • index.js (0 hunks)
  • jsx.js (0 hunks)
  • package.json (1 hunks)
  • src/base.ts (1 hunks)
  • src/import.ts (1 hunks)
  • src/index.ts (1 hunks)
  • src/jsx-a11y.ts (1 hunks)
  • src/react.ts (1 hunks)
  • src/stylistic.ts (1 hunks)
  • src/typescript.ts (1 hunks)
  • src/unused-imports.ts (1 hunks)
  • stylistic.js (0 hunks)
  • tsconfig.json (1 hunks)
  • typescript.js (0 hunks)
Files not reviewed due to no reviewable changes (6)
  • .eslintrc
  • base.js
  • index.js
  • jsx.js
  • stylistic.js
  • typescript.js
Files skipped from review due to trivial changes (3)
  • .gitignore
  • .npmrc
  • global.d.ts
Additional comments not posted (29)
.github/dependabot.yml (1)

1-8: LGTM!

The Dependabot configuration file is set up correctly:

  • The version is set to 2, which is the latest version of the configuration file format.
  • The updates section is correctly defined with the package-ecosystem set to "npm" and the directory set to "/".
  • The schedule section is correctly defined with the interval set to "daily".
  • The assignees section is correctly defined with the user "omermecitoglu" assigned to manage the updates.

This configuration will enable Dependabot to automatically check for dependency updates daily and create pull requests for any available updates. The assigned user will be notified of any updates and will be responsible for reviewing and merging the pull requests.

This setup will help keep the project's dependencies up-to-date and reduce the risk of security vulnerabilities and compatibility issues.

eslint.config.js (3)

1-2: LGTM!

The import statement is correctly importing the rules from the distribution module.


3-4: LGTM!

The ESLint configuration is correctly exported as an array, combining the imported rules with a custom rule set.


5-9: LGTM!

The custom rule set is correctly defined, enforcing the sorting of object keys in ascending order. This rule helps maintain code consistency and improves readability by ensuring object keys are organized in a predictable manner.

The rule options are appropriately specified:

  • "error" indicates that violations of this rule will be reported as errors.
  • "asc" specifies that the keys should be sorted in ascending order.
  • { caseSensitive: true, natural: false } configures the rule to be case-sensitive and use non-natural sorting.

These options align with the goal of promoting a consistent and readable code style.

src/unused-imports.ts (1)

1-16: LGTM! The configuration looks good and follows best practices.

The eslint-plugin-unused-imports plugin is a great addition to the ESLint setup. It helps maintain a clean codebase by enforcing rules related to unused imports and variables.

Here are some key benefits of using this plugin:

  1. Identifying unused imports: The no-unused-imports rule set to "error" will raise an error whenever there are unused imports in the codebase. This helps in removing unnecessary code and keeps the codebase tidy.

  2. Highlighting unused variables: The no-unused-vars rule set to "warn" will issue warnings for unused variables. This is useful for identifying variables that are declared but never used, allowing developers to clean up their code.

  3. Flexibility with unused parameters: The args: "after-used" option allows for unused arguments in functions if they come after used arguments. This provides flexibility in function parameter declarations.

  4. Ignoring intentionally unused variables: The argsIgnorePattern and varsIgnorePattern options allow for ignoring unused arguments and variables that start with an underscore. This is a common convention for intentionally unused parameters or variables, and it prevents unnecessary warnings.

Overall, this configuration promotes better coding practices, improves code maintainability, and helps catch potential issues related to unused code.

src/index.ts (2)

1-7: LGTM!

The imports are well-organized and cover various aspects of the codebase, such as base rules, stylistic conventions, TypeScript, React, accessibility, import statements, and unused imports. This modular approach allows for better maintainability and extensibility of the ESLint configuration.


9-17: LGTM!

The export statement consolidates all the imported configurations into a single array using the spread operator. This approach provides a unified configuration that can be easily imported and utilized elsewhere in the application. It enhances modularity and maintainability by allowing developers to manage and apply multiple sets of rules or configurations in a streamlined manner.

src/import.ts (1)

1-21: LGTM! The file structure and purpose are well-defined.

The file exports a default array containing a single configuration object that specifies plugins and rules for organizing imports. The configuration includes the import/order rule, which enforces a specific order for import statements based on predefined groups, allows for case-sensitive alphabetical ordering, and defines a path group for internal imports.

This setup aims to enhance code readability and maintainability by ensuring a consistent structure for import statements across the codebase.

src/react.ts (4)

6-6: LGTM!

The files section correctly specifies the file extensions for JavaScript and TypeScript files, including JSX and different module formats. The glob pattern ensures that the configuration applies to files in all directories and subdirectories.


7-16: LGTM!

The languageOptions section correctly sets up global variables for browser environments using the globals package. Enabling JSX syntax in the parserOptions is necessary for React projects. The configuration looks good.


17-19: LGTM!

The plugins section correctly includes the eslint-plugin-react plugin, which is essential for linting React code and enforcing best practices. The configuration looks good.


20-26: LGTM!

The rules section correctly defines the react/jsx-no-literals rule with an error severity. Allowing specific strings, such as "©", provides flexibility for commonly used entities or special characters. The rule enhances code quality by preventing the use of arbitrary string literals in JSX. The configuration looks good.

.github/workflows/release-package.yml (2)

18-19: LGTM!

Uncommenting the step to install dependencies is necessary for building and publishing the package. The npm install command is the correct way to install the required dependencies.


24-25: LGTM!

Uncommenting the step to build the package is necessary before publishing it to NPM. The npm run build command is the correct way to trigger the build process defined in the package.json file.

tsconfig.json (5)

2-22: LGTM!

The compilerOptions configuration looks good. It enables strict type checking, targets the latest ECMAScript version, and allows JavaScript files to be compiled alongside TypeScript files. The options are set to optimize for modern JavaScript development and ensure type safety.


19-21: LGTM!

The paths mapping is a nice addition. It allows for simplified imports from the src directory using a tilde (~) prefix, which can help keep import statements clean and consistent throughout the project.


23-25: LGTM!

The include configuration looks good. It ensures that all TypeScript files in the project are included in the compilation, which is a common pattern.


26-29: LGTM!

The exclude configuration looks good. Excluding the node_modules directory is a common pattern, as it contains third-party dependencies that don't need to be compiled. Excluding the configs directory suggests that it contains configuration files that don't need to be compiled.


1-30: Great work on the tsconfig.json file!

The TypeScript configuration file is comprehensive and well-structured. It includes a good set of compiler options that enable strict type checking, target the latest ECMAScript version, and allow JavaScript files to be compiled alongside TypeScript files.

The path mapping for simplified imports is a nice touch, and the include and exclude configurations follow common patterns and best practices.

Overall, the tsconfig.json file sets up a solid foundation for a modern and type-safe TypeScript project. Well done!

src/base.ts (1)

1-28: Excellent work on the ESLint configuration!

The configuration looks great and covers a wide range of best practices and potential issues. The rules are well-chosen and will help enforce a consistent coding style and catch potential issues early in the development process.

A few additional suggestions for improvement:

  • Consider adding rules for enforcing consistent naming conventions (e.g., camelcase for variables and functions, PascalCase for classes).
  • Consider adding rules for enforcing consistent formatting (e.g., indent, quotes, semi).
  • Consider adding rules for enforcing best practices around error handling (e.g., no-throw-literal, no-catch-shadow).
  • Consider adding rules for enforcing best practices around async/await (e.g., no-return-await, no-await-in-loop).

Overall, this is a solid configuration that will help improve code quality and maintainability. Great job!

src/typescript.ts (1)

1-38: Excellent ESLint configuration for TypeScript projects!

The provided ESLint configuration is well-structured and comprehensive, ensuring high code quality and maintainability in TypeScript projects. Here are some key highlights:

  • Extending the recommended rules from typescript-eslint provides a solid foundation of widely accepted best practices.
  • Specifying the applicable files and setting up the parser options ensures that the configuration is applied consistently across all TypeScript files.
  • The defined rules cover various aspects of TypeScript development, such as type consistency, error prevention, and code style. This promotes a clean and reliable codebase.
  • The use of different severity levels ("error" and "warn") allows for fine-grained control over rule violations, enabling a balance between strictness and flexibility.
  • Turning off specific rules, such as @typescript-eslint/no-unused-vars and class-methods-use-this, provides flexibility in scenarios where these rules may not be applicable or desired.

Overall, this ESLint configuration sets a strong foundation for maintaining a high-quality TypeScript codebase. Great job!

package.json (7)

3-3: LGTM!

The major version increment aligns with the significant changes made in the package, such as the updated dependencies and the introduction of the exports field.


6-7: LGTM!

The added keywords enhance the package's discoverability and accurately describe its purpose as a shareable ESLint configuration.


9-16: LGTM!

The added repository, bugs, and homepage metadata provide valuable information for users to access the source code, report issues, and view the package's documentation. This enhances the package's visibility and maintainability.


21-25: LGTM!

The restructured author object provides more comprehensive information about the package author, including their email and URL. This enhances the package's professionalism and credibility.


27-51: LGTM!

The use of ECMAScript modules, the updated main entry point, and the introduction of the exports field are positive changes that enhance the package's modularity, flexibility, and alignment with modern JavaScript development practices.


53-53: LGTM!

Including the entire dist/ directory in the files array simplifies the package distribution and ensures that all the necessary distribution files are included when the package is published.


60-74: LGTM!

The updated eslint peer dependency ensures compatibility with the latest ESLint releases. The updated dependencies bring new features and improvements to the package, such as added support for React-specific linting rules. The expanded devDependencies section enhances the package's development experience and type safety.

src/stylistic.ts (1)

4-123: LGTM!

The ESLint configuration object is comprehensive and well-structured. It covers a wide range of code style aspects and follows common best practices. The use of the @stylistic/eslint-plugin ensures that the rules are well-maintained and up to date.

Some notable aspects of the configuration:

  • It enforces consistent spacing and indentation rules, promoting readability.
  • It handles various edge cases and specific scenarios, such as JSX formatting and arrow function parentheses.
  • It allows some flexibility where appropriate, such as disabling the @stylistic/no-extra-parens rule.
  • It sets reasonable limits for line length and empty lines.

Overall, this configuration will help maintain a clean and consistent codebase.

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: 3

🧹 Outside diff range and nitpick comments (17)
src/unused-imports.ts (1)

9-15: LGTM: Rules are well-defined, with a suggestion for consideration.

The rule definitions are comprehensive and follow good practices:

  • unused-imports/no-unused-imports set to "error" ensures a clean codebase.
  • unused-imports/no-unused-vars set to "warn" with specific configurations provides flexibility while still highlighting potential issues.

The configuration for ignoring variables and arguments starting with underscore is a common and useful convention.

Consider setting unused-imports/no-unused-vars to "error" instead of "warn" for stricter enforcement. This change would align with the no-unused-imports rule and further improve code quality. Here's the suggested change:

 rules: {
   "unused-imports/no-unused-imports": "error",
   "unused-imports/no-unused-vars": [
-    "warn",
+    "error",
     { args: "after-used", argsIgnorePattern: "^_", vars: "all", varsIgnorePattern: "^_" },
   ],
 },
src/index.ts (2)

10-18: LGTM: Well-structured default export with a minor suggestion.

The default export effectively combines all the imported configurations into a single array, which is then correctly typed as Linter.Config[]. This structure allows for easy consumption of the entire ESLint configuration.

Consider adding a comment explaining the significance of the order in which the configurations are spread into the array, as ESLint applies rules in the order they appear. This would help future maintainers understand if the current order is intentional and why.


1-18: Well-structured configuration aggregator with room for future enhancements.

The overall structure of this file is clean and effective. It serves its purpose of aggregating multiple ESLint configurations into a single, easily importable module. The use of TypeScript for type safety is commendable.

For future considerations:

  1. As the project grows, you might want to add comments explaining the purpose of each configuration module and why they're included.
  2. Consider adding a mechanism for environment-specific configurations (e.g., development vs production) if needed in the future.
  3. If certain rules need to be conditionally applied based on project settings, you could introduce a factory function that generates the configuration array based on input parameters.
src/import.ts (1)

9-19: LGTM: Import order rule is well-configured, with a suggestion for improvement.

The import order rule configuration is comprehensive and follows best practices. It includes case-sensitive alphabetization, a well-defined group order, and a custom path group for internal imports.

However, I have a suggestion to improve the internal import pattern:

Consider making the internal import pattern more specific to your project structure. The current pattern "~/**" might be too broad. For example, if your internal modules are in a specific directory, you could use something like:

  pathGroups: [
-   { group: "internal", pattern: "~/**" },
+   { group: "internal", pattern: "@internal/**" },
  ],

This assumes your internal modules are in a directory that can be referenced with "@internal". Adjust the pattern to match your project's specific structure.

src/react.ts (3)

8-17: Language options look good, but consider specifying a parser.

The language options are well-configured:

  • Browser globals are correctly included, which is appropriate for most React projects.
  • JSX syntax is enabled in the parser options, which is necessary for React.

However, I noticed that a specific parser isn't specified. For React projects, especially those using TypeScript, it's often beneficial to use @typescript-eslint/parser.

Consider adding a parser specification to the configuration. Here's a suggested addition:

 languageOptions: {
   globals: {
     ...globals.browser,
   },
+  parser: "@typescript-eslint/parser",
   parserOptions: {
     ecmaFeatures: {
       jsx: true,
     },
+    ecmaVersion: "latest",
+    sourceType: "module",
   },
 },

This change ensures that TypeScript syntax is correctly parsed and adds some additional useful parser options.


18-20: Good inclusion of 'react' plugin, consider additional plugins for enhanced linting.

The inclusion of the 'eslint-plugin-react' is correct and necessary for React-specific linting rules.

For a more comprehensive React linting setup, consider adding these additional plugins:

  1. eslint-plugin-react-hooks: Enforces the Rules of Hooks.
  2. eslint-plugin-jsx-a11y: Checks accessibility rules on JSX elements.
  3. @typescript-eslint/eslint-plugin: If you're using TypeScript.

Here's how you might include these:

 plugins: {
   react,
+  "react-hooks": require("eslint-plugin-react-hooks"),
+  "jsx-a11y": require("eslint-plugin-jsx-a11y"),
+  "@typescript-eslint": require("@typescript-eslint/eslint-plugin"),
 },

Remember to also add the corresponding rules for these plugins in the rules section if you decide to include them.


21-27: Consider expanding the rule set for more comprehensive linting.

The inclusion of the 'react/jsx-no-literals' rule is a good start, as it can help enforce best practices for internationalization. However, the current configuration allowing only '©' as a literal might be overly restrictive for many projects.

  1. You might want to reconsider the allowed strings for 'react/jsx-no-literals' based on your project's needs.

  2. Consider adding more React-specific rules. Here are some suggestions:

rules: {
  "react/jsx-no-literals": ["error", {
    allowedStrings: [
      "&copy;",
      // Add more allowed strings as needed
    ],
  }],
  "react/prop-types": "error",
  "react/jsx-key": "error",
  "react/no-unused-state": "warn",
  "react/jsx-no-bind": ["warn", {
    allowArrowFunctions: true,
    allowFunctions: false,
    allowBind: false,
  }],
  "react/no-deprecated": "error",
  // Add more rules as needed
},
  1. If you decide to add the suggested plugins from the previous comment, you should also include their recommended rules:
rules: {
  // ... existing rules
  "react-hooks/rules-of-hooks": "error",
  "react-hooks/exhaustive-deps": "warn",
  "jsx-a11y/alt-text": "error",
  "jsx-a11y/anchor-has-content": "error",
  // ... more jsx-a11y rules
  "@typescript-eslint/explicit-function-return-type": "warn",
  "@typescript-eslint/no-explicit-any": "warn",
  // ... more @typescript-eslint rules
},

Remember to adjust these rules based on your specific project requirements and team preferences.

.github/workflows/release.yml (3)

13-20: Consider specifying a more precise Node.js version.

The current setup looks good, but using 'latest' for the Node.js version might lead to unexpected behavior if a new Node.js version is released with breaking changes.

Consider specifying a more precise version or version range. For example:

- node-version: 'latest'
+ node-version: '18.x'  # or another appropriate version

This ensures consistency across different runs of the workflow while still allowing for minor version updates.


36-40: Consider adding a semantic-release configuration file.

The semantic-release step is correctly set up with the necessary tokens. However, to ensure consistent and customized release behavior, it's recommended to add a configuration file.

Create a .releaserc.json file in your repository root with your desired configuration. For example:

{
  "branches": ["main"],
  "plugins": [
    "@semantic-release/commit-analyzer",
    "@semantic-release/release-notes-generator",
    "@semantic-release/npm",
    "@semantic-release/github"
  ]
}

This allows you to explicitly define the release behavior and ensures consistency across different environments.


1-40: Overall, good workflow structure with room for improvement.

The workflow covers the main steps required for a release process, which is great. However, there are a few areas for improvement:

  1. Implement testing steps before the release (as mentioned in a previous comment).
  2. Consider adding caching for the build output to speed up subsequent runs.
  3. You might want to add conditional steps to avoid unnecessary work. For example, only run the release step if tests pass and there are changes to release.

Here's an example of how you could implement caching for the build output:

- name: Cache build
  uses: actions/cache@v3
  with:
    path: dist  # adjust this to your build output directory
    key: ${{ runner.os }}-build-${{ hashFiles('**/package-lock.json') }}
    restore-keys: |
      ${{ runner.os }}-build-

- name: Build package
  run: npm run build

And here's how you could make the release step conditional:

- name: Run semantic-release
  if: success() && github.event_name == 'push'
  env:
    GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
    NPM_TOKEN: ${{ secrets.NPM_TOKEN }}
  run: npx semantic-release

These changes will make your workflow more efficient and robust.

package.json (3)

3-3: Approve major version bump to 2.0.0

The increment to version 2.0.0 is appropriate given the significant changes, particularly the update to ESLint 9 in peer dependencies.

Consider adding a CHANGELOG.md file or updating the existing one to document the breaking changes introduced in this version.


67-68: Approve script changes and suggest improvement

The addition of the "build" script using TypeScript compiler (tsc) is appropriate for generating the compiled distribution.

Consider adding a "prepublishOnly" script that runs both build and lint to ensure the package is properly prepared before publishing:

"scripts": {
  "build": "tsc",
  "lint": "eslint",
  "prepublishOnly": "npm run build && npm run lint"
}

71-71: Approve ESLint peer dependency update and suggest documentation

Updating the ESLint peer dependency to version 9 or higher is consistent with the package's major version bump.

Ensure that the README.md or documentation is updated to reflect this change in ESLint version requirement. Also, consider mentioning any breaking changes or migration steps for users upgrading from the previous version.

README.md (3)

27-27: Update to ESLint 9 flat config system

The README now mentions eslint.config.js or eslint.config.mjs as the configuration file names, reflecting the new flat config system introduced in ESLint 9. This is a significant change from the previous .eslintrc.* files.

Consider adding a note explaining this change for users upgrading from older versions, such as:

"Note: ESLint 9 introduces a new flat config system. If you're upgrading from an older version, you'll need to migrate your .eslintrc.* configuration to the new eslint.config.js or eslint.config.mjs format."


30-40: Approve new usage example with ES modules syntax

The new usage example correctly demonstrates the flat config system introduced in ESLint 9, using ES modules syntax. It effectively shows how to import and spread the configuration, and includes a placeholder for additional rules.

To further improve the example, consider adding a comment explaining the spread operator for less experienced users:

import omer from "@omer-x/eslint-config";

export default [
  ...omer, // Spread the imported configuration
  {
    rules: {
      // Add your custom rules here to override or extend the imported configuration
    },
  },
];

42-66: Approve addition of individual component usage example

The new example effectively demonstrates how to import and use individual components of the ESLint configuration. This provides users with more flexibility in customizing their setup.

To enhance this section:

  1. Consider adding a brief explanation of each component's purpose at the beginning of this section.
  2. Add a note about the importance of component order:

"Note: The order in which you spread the components may affect rule precedence. Components listed later in the array will override conflicting rules from earlier components."

This will help users understand how to effectively combine and prioritize different rule sets.

src/stylistic.ts (1)

9-123: Consider adding documentation for certain rules.

While the rules are well-defined, some might benefit from additional explanation or justification, especially for team members who might be new to these conventions. Consider adding comments for rules that:

  1. Deviate from common defaults
  2. Have complex configurations
  3. Are specific to your project's needs

For example, you could add a comment explaining the rationale behind the "@stylistic/jsx-curly-brace-presence" rule configuration.

📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

📥 Commits

Files that changed from the base of the PR and between 1a0d571 and 4741992.

⛔ Files ignored due to path filters (1)
  • package-lock.json is excluded by !**/package-lock.json
📒 Files selected for processing (14)
  • .github/workflows/release-package.yml (0 hunks)
  • .github/workflows/release.yml (1 hunks)
  • README.md (1 hunks)
  • global.d.ts (1 hunks)
  • package.json (1 hunks)
  • src/base.ts (1 hunks)
  • src/import.ts (1 hunks)
  • src/index.ts (1 hunks)
  • src/jsx-a11y.ts (1 hunks)
  • src/react.ts (1 hunks)
  • src/stylistic.ts (1 hunks)
  • src/typescript.ts (1 hunks)
  • src/unused-imports.ts (1 hunks)
  • tsconfig.json (1 hunks)
💤 Files with no reviewable changes (1)
  • .github/workflows/release-package.yml
✅ Files skipped from review due to trivial changes (2)
  • global.d.ts
  • tsconfig.json
🔇 Additional comments (32)
src/jsx-a11y.ts (4)

1-2: LGTM: Imports are correct and well-structured.

The imports are appropriate for the ESLint configuration with jsx-a11y. Good job on importing the Linter type for better type checking.


4-6: LGTM: Well-structured ESLint configuration.

The configuration array is well-structured, combining the recommended jsx-a11y rules with custom overrides. This approach allows for easy maintenance and extension of the ESLint setup.

Also applies to: 10-11


7-9: Consider using the ignoreNonDOM option for the jsx-a11y/no-autofocus rule.

Instead of turning off the jsx-a11y/no-autofocus rule globally, consider using the ignoreNonDOM option to allow autofocus on non-DOM elements. This approach ensures that accessibility standards are maintained while accommodating specific use cases.

Apply this diff to update the configuration:

  rules: {
-   "jsx-a11y/no-autofocus": "off",
+   "jsx-a11y/no-autofocus": ["error", { ignoreNonDOM: true }],
  },

11-11: LGTM: Proper type assertion for ESLint configuration.

The type assertion to Linter.Config[] is correct and helps ensure type safety. This will catch potential configuration errors at compile-time, which is a good practice.

src/unused-imports.ts (5)

1-2: LGTM: Imports are correctly defined.

The import statements are properly structured, importing the necessary plugin and type definition for the ESLint configuration.


4-17: LGTM: Configuration export structure is correct.

The configuration is exported as an array, which is a good practice for potential future extensibility. The single configuration object within the array follows the correct ESLint configuration structure.


6-8: LGTM: Plugin is correctly configured.

The unused-imports plugin is properly specified in the plugins section, allowing ESLint to utilize the rules defined by this plugin.


17-17: LGTM: Type assertion enhances type safety.

The type assertion as Linter.Config[] ensures type safety for the ESLint configuration. This practice improves IDE support and helps catch potential configuration errors early in the development process.


1-17: Overall assessment: Well-implemented ESLint configuration for unused imports.

This new file introduces a robust ESLint configuration for managing unused imports. The implementation is correct, type-safe, and follows good practices. The configuration effectively utilizes the eslint-plugin-unused-imports plugin and defines appropriate rules for maintaining clean code.

The only suggestion for improvement is to consider making the unused-imports/no-unused-vars rule stricter by changing it from "warn" to "error", as mentioned in a previous comment.

Great job on implementing this ESLint configuration!

src/index.ts (2)

1-7: LGTM: Imports are well-organized and comprehensive.

The imports cover various aspects of ESLint configuration, including base rules, React, TypeScript, and other plugins. The naming is consistent and clear, making the purpose of each import evident.


8-8: Good use of type import.

Importing the Linter type from 'eslint' demonstrates good TypeScript practices, ensuring type safety for the ESLint configuration.

src/import.ts (3)

1-2: LGTM: Import statements are correct and necessary.

The import statements are properly structured, importing the necessary plugin and type definition for the ESLint configuration.


4-8: LGTM: Export and configuration structure are well-defined.

The export statement and configuration object structure follow ESLint best practices. The use of an array allows for potential future expansion, and the type assertion ensures type safety.

Also applies to: 20-22


1-22: Overall assessment: Well-structured ESLint configuration for import ordering.

This new file introduces a well-structured ESLint configuration for import ordering. The configuration is comprehensive, type-safe, and follows best practices. It provides a solid foundation for maintaining consistent import ordering in the project.

The only suggested improvement is to consider refining the internal import pattern to better match your project's specific structure.

src/react.ts (3)

1-3: LGTM: Imports are appropriate and correctly structured.

The imports are well-organized and include all necessary dependencies for the ESLint configuration:

  1. eslint-plugin-react for React-specific rules
  2. globals for setting up browser globals
  3. Linter type from eslint for type annotations

5-29: LGTM: Well-structured export of the ESLint configuration.

The export statement is correctly structured:

  • Exporting as an array allows for potential future expansion with multiple configurations.
  • The type-cast to Linter.Config[] ensures type safety and improves IDE support.

7-7: LGTM: Comprehensive file pattern coverage.

The file pattern "**/*.{js,jsx,mjs,cjs,ts,tsx}" effectively covers all common JavaScript and TypeScript file extensions, including:

  • Standard JavaScript (.js)
  • JSX files (.jsx)
  • ECMAScript modules (.mjs)
  • CommonJS modules (.cjs)
  • TypeScript (.ts)
  • TypeScript with JSX (.tsx)

This ensures that the ESLint configuration will be applied to all relevant files in a React project.

.github/workflows/release.yml (1)

1-12: LGTM: Workflow setup looks good.

The workflow trigger and job setup are well-configured:

  • Triggering on pushes to the main branch is appropriate for a release workflow.
  • Using ubuntu-latest ensures an up-to-date environment.
  • The contents: write permission is correctly set, which is necessary for creating releases.
src/base.ts (5)

1-2: LGTM: Imports are correct and follow best practices.

The imports are appropriate for creating an ESLint configuration. Using a named import for the Linter type is a good TypeScript practice.


4-6: LGTM: Configuration structure is correct.

The configuration structure follows ESLint's recommended format:

  1. It extends the recommended configuration.
  2. It provides custom rules.

This approach ensures a solid baseline while allowing for project-specific customizations.

Also applies to: 28-29


7-27: LGTM: Well-configured ESLint rules.

The custom rules are well-chosen and correctly configured. They enforce good coding practices such as:

  • Proper use of array callbacks and class methods
  • Consistent code style (curly braces, dot notation)
  • Strict equality checks
  • Limited nesting and complexity
  • ES6+ features (const/let over var)
  • Clean imports and exports

The warning for console statements and require-await is a good balance between strictness and practicality during development.


29-29: LGTM: Appropriate type assertion.

The type assertion as Linter.Config[] is correct and beneficial. It ensures type safety and provides better IDE support for the ESLint configuration.


1-29: Excellent ESLint configuration setup.

This ESLint configuration is well-structured, comprehensive, and follows best practices:

  1. It extends the recommended configuration for a solid baseline.
  2. Custom rules are thoughtfully chosen and configured.
  3. The configuration is properly typed for better tooling support.

The balance between strict rules and practical warnings (e.g., for console statements) is appropriate for most development scenarios. This configuration will significantly contribute to maintaining high code quality and consistency.

package.json (4)

6-7: Approve keyword updates

The updated keywords "eslint-config" and "shareable-config" are more specific and align better with ESLint configuration package conventions.


9-16: Approve addition of metadata fields

The new repository, bugs, homepage, and expanded author information enhance the package's metadata and improve its discoverability on npm and GitHub.

Also applies to: 21-25


74-80: Approve dependency updates and suggest compatibility check

The updates to dependencies and devDependencies align with the move to ESLint 9 and improved TypeScript support. The addition of React-related plugins expands the configuration's functionality.

Please verify the compatibility of all updated and new dependencies. Run the following script to check for any peer dependency warnings or version conflicts:

#!/bin/bash
# Verify dependency compatibility
npm install
if [ $? -eq 0 ]; then
  echo "Dependencies installed successfully."
  npm ls
else
  echo "Error: Dependency installation failed. Check for compatibility issues."
  exit 1
fi

Also applies to: 83-86


27-62: Approve package structure changes and suggest verification

The updated package structure, including the "type": "module" declaration, new main entry point, and detailed exports field, indicates a transition to a compiled distribution with ES module support. This is a positive change that allows for better tree-shaking and module resolution.

Please ensure that the compiled distribution in the dist/ directory is included in the repository or generated during the CI/CD process. Run the following script to verify the presence of the distribution files:

Also applies to: 64-64

✅ Verification successful

Package structure changes verified successfully.

  • The dist directory is correctly ignored and is generated via the build script.
🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Verify the presence of distribution files
if [ -d "dist" ]; then
  echo "Distribution directory exists."
  ls -R dist
else
  echo "Error: Distribution directory 'dist' not found."
  exit 1
fi

Length of output: 264


Script:

#!/bin/bash
# Verify the presence of distribution directory without using npm
if [ -d "dist" ]; then
  echo "Distribution directory exists."
  ls -R dist
else
  echo "Error: Distribution directory 'dist' not found."
  exit 1
fi

Length of output: 137


Script:

#!/bin/bash
# Check for build scripts in package.json
if grep -q '"build"' package.json; then
  echo "Build script found in package.json."
  # Display the build script command
  grep '"build"' package.json | awk -F: '{print $2}' | tr -d '", '
else
  echo "No build script found in package.json."
  exit 1
fi

# Check if 'dist' is tracked by Git
git ls-files --error-unmatch dist > /dev/null 2>&1
if [ $? -eq 0 ]; then
  echo "'dist' directory is tracked by Git."
else
  echo "'dist' directory is not tracked by Git."
fi

Length of output: 333


Script:

#!/bin/bash
# Check if 'dist' is listed in .gitignore
if [ -f ".gitignore" ]; then
  if grep -qw "dist" .gitignore; then
    echo "'dist' directory is correctly listed in .gitignore."
  else
    echo "Warning: 'dist' directory is NOT listed in .gitignore."
    exit 1
  fi
else
  echo "Error: .gitignore file not found."
  exit 1
fi

Length of output: 169

README.md (1)

23-23: Significant update in ESLint version requirement

The ESLint version requirement has been updated from ">= 8" to ">= 9". This is a major version change that may include breaking changes. Ensure that your project and all dependencies are compatible with ESLint 9.

To verify the impact of this change, run the following script:

✅ Verification successful

ESLint 9 Upgrade Compatibility Verified

All listed ESLint plugins are up-to-date and appear compatible with ESLint 9. Ensure to review each plugin's documentation for any specific migration guidelines or compatibility notes.

🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Check for potential compatibility issues with ESLint 9

# Test: Search for ESLint configuration files
echo "Searching for ESLint configuration files..."
fd -e js -e json -e yaml -e yml -e cjs -e mjs '(\.eslintrc|eslint\.config)' -x echo "Found ESLint config: {}"

# Test: Check for deprecated rules or plugins
echo "Checking for potentially deprecated rules or plugins..."
rg -i '(rules?|plugins?|extends?)' -g '*.{js,json,yaml,yml,cjs,mjs}'

# Note: This script provides a starting point for manual review.
# You may need to check the ESLint 9 migration guide for specific changes.

Length of output: 3915


Script:

#!/bin/bash
# Description: List versions of all ESLint plugins to verify compatibility with ESLint 9

echo "Extracting ESLint plugin versions from package.json and package-lock.json..."

# Extract ESLint plugins from package.json
echo "ESLint plugins in package.json:"
grep -E '"eslint-plugin-[^"]+"' package.json | awk -F'"' '{print $4 ": " $6}'

# Extract ESLint plugins from package-lock.json
echo -e "\nESLint plugins in package-lock.json:"
grep -E '"eslint-plugin-[^"]+"' package-lock.json | awk -F'"' '{print $4 ": " $6}'

Length of output: 567


Script:

#!/bin/bash
# Description: Correctly list names and versions of all ESLint plugins to verify compatibility with ESLint 9

echo "Extracting ESLint plugin names and versions from package.json and package-lock.json..."

# Function to extract plugin names and versions
extract_plugins() {
  local file=$1
  grep -E '"eslint-plugin-[^"]+"' "$file" | sed -E 's/.*"?(eslint-plugin-[^"]+)"?:\s*"([^"]+)".*/\1: \2/'
}

# Extract ESLint plugins from package.json
echo "ESLint plugins in package.json:"
extract_plugins package.json

# Extract ESLint plugins from package-lock.json
echo -e "\nESLint plugins in package-lock.json:"
extract_plugins package-lock.json

Length of output: 951

src/stylistic.ts (4)

1-2: LGTM: Imports are correct and follow good practices.

The imports are appropriate for the ESLint configuration:

  1. Importing stylistic from "@stylistic/eslint-plugin" for the plugin.
  2. Importing the Linter type from "eslint" for type checking.

Using a named import for stylistic and a type import for Linter follows good TypeScript practices.


4-5: LGTM: Export structure is correct for ESLint configuration.

The export structure is appropriate:

  1. Exporting a default array containing the configuration object.
  2. Casting the export as Linter.Config[] ensures type safety and compatibility with ESLint.

This structure allows for easy import and use of the configuration in other files.

Also applies to: 124-125


6-8: LGTM: Plugin configuration is correct.

The plugins section correctly includes the @stylistic plugin and associates it with the imported stylistic module. This setup allows the use of all the stylistic rules defined in the configuration.


9-123: LGTM: Comprehensive set of stylistic rules.

The rules configuration is extensive and covers a wide range of stylistic aspects, including spacing, indentation, formatting, and JSX-specific rules. The majority of rules being set to "error" ensures strict adherence to the defined style guide.

@omermecitoglu omermecitoglu merged commit 5376b07 into main Oct 4, 2024
1 check passed
@omermecitoglu omermecitoglu deleted the 1-migration-to-eslint-9 branch October 4, 2024 05:39
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Migration to eslint 9
1 participant