3.5.0 • Published 6 months ago

momenti-eslint v3.5.0

Weekly downloads
-
License
ISC
Repository
gitlab
Last release
6 months ago

momenti-eslint

A shareable ESLint configuration for Next.js projects using TypeScript, TSX, JavaScript, and JSX. Designed with modern best practices, accessibility, and maintainability in mind.

Features

  • Optimized for Next.js + TypeScript + React projects
  • Balanced rule set for good code quality without being too strict
  • Performance optimized for faster linting
  • Built-in Prettier integration
  • Accessibility (a11y) rules included
  • Unused imports detection
  • SVG imports support

Installation

# Using npm
npm install --save-dev momenti-eslint

# Using yarn
yarn add --dev momenti-eslint

# Using pnpm
pnpm add -D momenti-eslint

# Using bun
bun add -D momenti-eslint

Next.js Setup

This ESLint configuration is optimized for Next.js projects. Follow these steps for the best setup:

  1. Install the package and its peer dependencies:
# Using npm
npm install --save-dev momenti-eslint @typescript-eslint/eslint-plugin @typescript-eslint/parser eslint eslint-config-next @next/eslint-plugin-next eslint-plugin-import eslint-plugin-jsx-a11y eslint-plugin-prettier eslint-plugin-react eslint-plugin-react-hooks

# Using yarn
yarn add -D momenti-eslint @typescript-eslint/eslint-plugin @typescript-eslint/parser eslint eslint-config-next @next/eslint-plugin-next eslint-plugin-import eslint-plugin-jsx-a11y eslint-plugin-prettier eslint-plugin-react eslint-plugin-react-hooks
  1. Create an eslint.config.mjs file in your project root:
import momentiEslintConfig from 'momenti-eslint';

export default [...momentiEslintConfig];
  1. Add the following to your package.json:
{
  "scripts": {
    "lint": "eslint --config eslint.config.mjs .",
    "lint:fix": "eslint --config eslint.config.mjs . --fix"
  }
}
  1. For proper SVG imports support, update your next.config.js:
/** @type {import('next').NextConfig} */
const nextConfig = {
  webpack(config) {
    // SVG Configuration
    config.module.rules.push({
      test: /\.svg$/,
      use: ['@svgr/webpack'],
    });
    return config;
  },
};

export default nextConfig;
  1. Install SVGR for Next.js:
npm install --save-dev @svgr/webpack

Usage

Create an eslint.config.mjs file in your project root:

import momentiEslintConfig from 'momenti-eslint';

export default [...momentiEslintConfig];

TypeScript Configuration

For proper TypeScript support, especially with SVG imports, create or update your tsconfig.json:

{
  "compilerOptions": {
    "target": "es5",
    "lib": ["dom", "dom.iterable", "esnext"],
    "allowJs": true,
    "skipLibCheck": true,
    "strict": true,
    "forceConsistentCasingInFileNames": true,
    "noEmit": true,
    "esModuleInterop": true,
    "module": "esnext",
    "moduleResolution": "bundler",
    "resolveJsonModule": true,
    "isolatedModules": true,
    "jsx": "preserve",
    "incremental": true,
    "plugins": [
      {
        "name": "next"
      }
    ],
    "paths": {
      "@/*": ["./*"]
    }
  },
  "include": ["next-env.d.ts", "**/*.ts", "**/*.tsx", ".next/types/**/*.ts"],
  "exclude": ["node_modules"]
}

SVG Type Declarations

To properly type SVG imports and icon objects, create a types.d.ts file in your project:

declare module '*.svg' {
  import * as React from 'react';
  const ReactComponent: React.FunctionComponent<React.SVGProps<SVGSVGElement>>;
  export default ReactComponent;
}

// For icon objects that reference SVG files
declare module '@/constants/icons' {
  const Icons: {
    [key: string]: React.FunctionComponent<React.SVGProps<SVGSVGElement>>;
  };
  export default Icons;
}

Development vs Production

The configuration automatically detects the NODE_ENV environment variable:

  • In development: Type checking is disabled for faster linting
  • In production: Full type checking is enabled

To run linting in development mode:

NODE_ENV=development eslint .

To run linting in production mode with full type checking:

NODE_ENV=production eslint .

What’s Included?

Installed Dependencies:

Included Dependencies

The following dependencies are included in this package to ensure proper linting rules are applied:

DependencyPurpose
@eslint/eslintrcFor FlatCompat, enabling modern configs.
@typescript-eslint/eslint-pluginTypeScript-specific linting rules.
@typescript-eslint/parserParses TypeScript code for ESLint.
eslintCore linting engine.
eslint-config-nextNext.js-specific linting rules.
@next/eslint-plugin-nextNext.js-specific linting rules.
eslint-plugin-importRules for ES module imports.
eslint-plugin-jsx-a11yAccessibility rules for JSX elements.
eslint-plugin-prettierIntegrates Prettier for formatting rules.
eslint-plugin-reactReact-specific linting rules.
eslint-plugin-react-hooksEnsures proper use of React Hooks.
globalsDefines browser and Node.js global variables.
prettierCode formatter integration.

Changelog

The changelog is automatically generated following Conventional Commits. See the CHANGELOG.md file for detailed updates.

npm Package

You can find the npm package here.

npm version

PUBLISHING NEW VERSIONS

To publish a new version, run the following commands:

npm run release

This will create a new version, push to GitHub, and publish to npm.

or

npm run release:patch
npm run release:minor
npm run release:major

or you can also use npm publish directly after updating the version in package.json with npm version patch or npm version minor or npm version major.

License

ISC

3.5.0

6 months ago

3.4.0

6 months ago

3.3.0

6 months ago

3.2.0

6 months ago

3.1.0

6 months ago

3.0.0

6 months ago

1.2.8

8 months ago

1.2.7

8 months ago

1.2.6

8 months ago

1.2.5

8 months ago

1.2.4

8 months ago

1.2.3

8 months ago

1.2.2

8 months ago

1.2.1

8 months ago

1.2.0

8 months ago

1.1.0

8 months ago

1.0.4

8 months ago

1.0.3

8 months ago

1.0.2

8 months ago

1.0.1

8 months ago