Skip to content

linter: various rules are missing options documentation on the Rules pages of the website #14743

@connorshea

Description

@connorshea

I think this was covered slightly by #6050, but may have been missed as being within scope of the problem.

no-unused-vars, for example, has various options available. But the page for the rule makes no mention of them.

The same is true with max-classes-per-file, which has options for ignoreExpressions and max, but no mention of that in the documentation.

It might be good to enforce this somehow via a check, but I'm not really familiar enough with rust to say how.

Here's a script to get all rules without the autogenerated config set up, but that do have configuration options:

Script for finding lint rules with options but no autogen config
#!/usr/bin/env node
// Find eslint rule files that have from_configuration
// but no "config =" in declare_oxc_lint!

import fs from 'fs';
import path from 'path';
import { fileURLToPath } from 'url';

const __filename = fileURLToPath(import.meta.url);
const __dirname = path.dirname(__filename);

const RULES_DIR = path.join(__dirname, 'crates/oxc_linter/src/rules');

function scanDirectory(dir) {
  const files = fs.readdirSync(dir, { withFileTypes: true });
  const results = [];

  for (const file of files) {
    const fullPath = path.join(dir, file.name);

    if (file.isDirectory()) {
      // Recursively scan subdirectories
      results.push(...scanDirectory(fullPath));
    } else if (file.isFile() && file.name.endsWith('.rs')) {
      const content = fs.readFileSync(fullPath, 'utf8');

      const hasDeclareLint = content.includes('declare_oxc_lint!(');
      const hasFromConfig = content.includes('fn from_configuration(');
      const hasConfigParam = (/^\s*config\s*=\s/m).test(content);

      if (hasDeclareLint && hasFromConfig && !hasConfigParam) {
        results.push(path.relative(__dirname, fullPath));
      }
    }
  }

  return results;
}

const missingFiles = scanDirectory(RULES_DIR);

if (missingFiles.length === 0) {
  console.log('No files found missing config parameter.');
} else {
  // Group by plugin (first directory under crates/oxc_linter/src/rules)
  const groups = new Map();

  // Normalize, compute path relative to RULES_DIR, and bucket by plugin
  missingFiles.sort().forEach(file => {
    const absPath = path.join(__dirname, file);
    const relToRules = path.relative(RULES_DIR, absPath);
    const parts = relToRules.split(path.sep);
    const plugin = parts[0] || 'unknown';

    if (!groups.has(plugin)) groups.set(plugin, []);
    groups.get(plugin).push(relToRules);
  });

  console.log('Files with declare_oxc_lint! and from_configuration but missing "config =" (grouped by plugin):');
  console.log('');

  // Print per-plugin breakdown (alphabetical), with sorted file lists
  const pluginNames = Array.from(groups.keys()).sort();
  for (const plugin of pluginNames) {
    const files = groups.get(plugin).sort();
    console.log(`${plugin} (${files.length})`);
    for (const f of files) {
      console.log(`- [ ] ${f}`);
    }
    console.log('');
  }

  const pluginCount = pluginNames.length;
  console.log(`Total: ${missingFiles.length} files across ${pluginCount} plugin${pluginCount === 1 ? '' : 's'}`);
}

This is not going to be perfect, but it works pretty well. It is absolutely possible that a rule would have config = but no doc comments for each option, and so wouldn't really be complete. That case would be missed entirely by this script.

Current list of rules that need to be updated (155 files):

If you use Copilot or a similar tool, you can also use this prompt file that I have put together. It works fairly well with VS Code + GitHub Copilot, if you have access to it. You can use "Run Prompt" in the command palette to create a prompt file and then run it.

Metadata

Metadata

Assignees

Labels

A-linterArea - Lintergood first issueExperience Level - Good for newcomers

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions