{"id":19959,"library":"eslint-plugin-ternaries","title":"eslint-plugin-ternaries","description":"An ESLint plugin that provides rules specifically for controlling the use of ternary expressions in JavaScript. The current stable version is 1.1.0, which adds the no-empty-ternary rule to complement the existing no-null-ternary rule. This plugin is designed for teams that want to enforce coding standards around ternaries, such as disallowing null or empty string values in ternary branches. It is a lightweight plugin with no additional dependencies besides ESLint itself.","status":"active","version":"1.1.0","language":"javascript","source_language":"en","source_url":"https://github.com/divyagnan/eslint-plugin-ternaries","tags":["javascript","eslint","eslintplugin","eslint-plugin","ternary","no-null"],"install":[{"cmd":"npm install eslint-plugin-ternaries","lang":"bash","label":"npm"},{"cmd":"yarn add eslint-plugin-ternaries","lang":"bash","label":"yarn"},{"cmd":"pnpm add eslint-plugin-ternaries","lang":"bash","label":"pnpm"}],"dependencies":[],"imports":[{"note":"The plugin is registered in ESLint config, not imported in code.","wrong":"// npm install eslint-plugin-ternaries --save-dev (forgetting to add to plugins)","symbol":"Plugin","correct":"// .eslintrc: { \"plugins\": [\"ternaries\"] }"},{"note":"Rules must be prefixed with the plugin name 'ternaries/'.","wrong":"{ \"rules\": { \"no-null-ternary\": \"error\" } }","symbol":"no-null-ternary","correct":"// .eslintrc: { \"rules\": { \"ternaries/no-null-ternary\": \"error\" } }"},{"note":"Severity levels: 0=off, 1=warn, 2=error. Common mistake is using numbers or strings incorrectly.","wrong":"{ \"rules\": { \"ternaries/no-empty-ternary\": \"error\", \"ternaries/no-null-ternary\": 2 } }","symbol":"no-empty-ternary","correct":"// .eslintrc: { \"rules\": { \"ternaries/no-empty-ternary\": \"warn\" } }"}],"quickstart":{"code":"// Step 1: Install ESLint and the plugin\nnpm install eslint --save-dev\nnpm install eslint-plugin-ternaries --save-dev\n\n// Step 2: Create .eslintrc.json\n{\n  \"plugins\": [\"ternaries\"],\n  \"rules\": {\n    \"ternaries/no-null-ternary\": \"error\",\n    \"ternaries/no-empty-ternary\": \"warn\"\n  }\n}\n\n// Step 3: Test with a file\nconst x = condition ? null : 1; // Error: ternaries/no-null-ternary\nconst y = condition ? '' : 2;   // Warning: ternaries/no-empty-ternary","lang":"javascript","description":"Shows installation, configuration in .eslintrc, and example violations."},"warnings":[{"fix":"Use 'ternaries/no-null-ternary' instead of just 'no-null-ternary'.","message":"Rules must be prefixed with 'ternaries/' in ESLint configuration.","severity":"gotcha","affected_versions":">=0.0.0"},{"fix":"Ensure ESLint is installed in your project.","message":"ESLint required as peer dependency. Plugin will not work without ESLint.","severity":"breaking","affected_versions":">=1.0.0"},{"fix":"Use correct severity: 'error', 'warn', or 'off'.","message":"Severity values: 0 (off), 1 (warn), 2 (error) or strings 'off', 'warn', 'error'. Do not use other numbers.","severity":"gotcha","affected_versions":">=0.0.0"}],"env_vars":null,"last_verified":"2026-04-25T00:00:00.000Z","next_check":"2026-07-24T00:00:00.000Z","problems":[{"fix":"Run 'npm install eslint-plugin-ternaries --save-dev'.","cause":"Plugin not installed in node_modules.","error":"Error: Failed to load plugin 'ternaries': Cannot find module 'eslint-plugin-ternaries'"},{"fix":"Use 'ternaries/no-null-ternary' instead of 'no-null-ternary'.","cause":"Rule missing 'ternaries/' prefix in ESLint config.","error":"Error: Failed to load rule 'no-null-ternary'"}],"ecosystem":"npm","meta_description":null,"install_score":null,"install_tag":null,"quickstart_score":null,"quickstart_tag":null}