Using Linting Tools to Enforce Coding Standards
Implement tools like ESLint effectively to maintain style and consistent coding practices across JavaScript files.
0 likes
4 views
Rule Content
{ "title": "Using Linting Tools to Enforce Coding Standards", "description": "Implement tools like ESLint effectively to maintain style and consistent coding practices across JavaScript files.", "category": "JavaScript Cursor Rules", "rules": [ { "name": "Enable ESLint with Recommended Configurations", "description": "Ensure ESLint is enabled with the recommended configurations to enforce best practices and coding standards.", "implementation": { "type": "eslint", "config": { "extends": [ "eslint:recommended", "plugin:@typescript-eslint/recommended", "plugin:react/recommended", "prettier" ], "parser": "@typescript-eslint/parser", "parserOptions": { "ecmaVersion": 2021, "sourceType": "module", "ecmaFeatures": { "jsx": true } }, "plugins": [ "@typescript-eslint", "react", "prettier" ], "rules": { "no-console": "warn", "no-unused-vars": "warn", "prefer-const": "error", "eqeqeq": "error", "react/jsx-uses-react": "off", "react/react-in-jsx-scope": "off", "prettier/prettier": [ "error", { "singleQuote": true, "semi": false, "trailingComma": "es5" } ] } } } }, { "name": "Integrate ESLint with Prettier", "description": "Integrate ESLint with Prettier to ensure consistent code formatting and avoid conflicts between the two tools.", "implementation": { "type": "eslint", "config": { "extends": [ "prettier" ], "plugins": [ "prettier" ], "rules": { "prettier/prettier": [ "error", { "singleQuote": true, "semi": false, "trailingComma": "es5" } ] } } } }, { "name": "Configure ESLint for React Projects", "description": "Configure ESLint specifically for React projects to enforce React best practices and coding standards.", "implementation": { "type": "eslint", "config": { "extends": [ "plugin:react/recommended" ], "plugins": [ "react" ], "rules": { "react/jsx-uses-react": "off", "react/react-in-jsx-scope": "off", "react/prop-types": "warn" } } } }, { "name": "Set Up ESLint for TypeScript", "description": "Set up ESLint to work with TypeScript, ensuring type safety and adherence to TypeScript best practices.", "implementation": { "type": "eslint", "config": { "extends": [ "plugin:@typescript-eslint/recommended" ], "parser": "@typescript-eslint/parser", "plugins": [ "@typescript-eslint" ], "rules": { "@typescript-eslint/no-explicit-any": "warn", "@typescript-eslint/no-unused-vars": [ "error", { "args": "none", "caughtErrors": "none" } ] } } } }, { "name": "Enforce Consistent Code Style", "description": "Enforce a consistent code style across the project to improve readability and maintainability.", "implementation": { "type": "eslint", "config": { "rules": { "indent": [ "error", 2 ], "quotes": [ "error", "single" ], "semi": [ "error", "always" ], "comma-dangle": [ "error", "never" ], "linebreak-style": [ "error", "unix" ], "object-curly-spacing": [ "error", "always" ], "array-bracket-spacing": [ "error", "always" ], "arrow-spacing": [ "error", { "before": true, "after": true } ], "space-before-function-paren": [ "error", "always" ], "camelcase": [ "error", { "properties": "always" } ], "func-names": [ "error", "never" ], "no-func-assign": "error", "max-len": [ "error", { "code": 120 } ], "sort-keys": [ "error", "asc", { "caseSensitive": true, "natural": false } ], "no-magic-numbers": [ "error", { "ignore": [ -1, 0, 1 ] } ], "import/order": [ "error", { "newlines-between": "always" } ], "no-duplicate-imports": "error", "lines-between-class-members": [ "error", "always" ], "require-jsdoc": [ "warn", { "require": { "FunctionDeclaration": true, "MethodDefinition": true, "ClassDeclaration": true } } ], "no-unused-expressions": [ "warn", { "allowShortCircuit": true, "allowTernary": true } ] } } } } ] }