### Install with pnpm Source: https://github.com/joshuakgoldberg/eslint-plugin-erasable-syntax-only/blob/main/_autodocs/usage-guide.md Install the plugin as a development dependency using pnpm. ```bash pnpm add -D eslint-plugin-erasable-syntax-only ``` -------------------------------- ### Install with yarn Source: https://github.com/joshuakgoldberg/eslint-plugin-erasable-syntax-only/blob/main/_autodocs/usage-guide.md Install the plugin as a development dependency using yarn. ```bash yarn add --dev eslint-plugin-erasable-syntax-only ``` -------------------------------- ### Install with npm Source: https://github.com/joshuakgoldberg/eslint-plugin-erasable-syntax-only/blob/main/_autodocs/usage-guide.md Install the plugin as a development dependency using npm. ```bash npm install --save-dev eslint-plugin-erasable-syntax-only ``` -------------------------------- ### Install ESLint Plugin Source: https://github.com/joshuakgoldberg/eslint-plugin-erasable-syntax-only/blob/main/README.md Install the plugin as a development dependency using npm. ```shell npm i eslint-plugin-erasable-syntax-only -D ``` -------------------------------- ### Default Import Example Source: https://github.com/joshuakgoldberg/eslint-plugin-erasable-syntax-only/blob/main/_autodocs/api-reference.md Demonstrates how to import the plugin using a default import and configure it in an ESLint configuration object. ```javascript import erasableSyntaxOnly from "eslint-plugin-erasable-syntax-only"; export default defineConfig({ plugins: { "erasable-syntax-only": erasableSyntaxOnly, }, }); ``` -------------------------------- ### Plugin Object Example Source: https://github.com/joshuakgoldberg/eslint-plugin-erasable-syntax-only/blob/main/_autodocs/api-reference.md Configure ESLint to use the plugin by including it in the plugins object. ```javascript import { plugin } from "eslint-plugin-erasable-syntax-only"; export default { plugins: { "erasable-syntax-only": plugin, }, }; ``` -------------------------------- ### Example Usage of GreetOptions Source: https://github.com/joshuakgoldberg/eslint-plugin-erasable-syntax-only/blob/main/_autodocs/types.md Demonstrates how to use the GreetOptions interface with a hypothetical greet function. Shows default value handling for optional properties. ```typescript function greet(options: GreetOptions) { const logger = options.logger || console.log; const times = options.times ?? 1; for (let i = 0; i < times; i++) { logger(options.message); } } // Usage greet({ message: "Hello, world!", logger: console.log, times: 3, }); ``` -------------------------------- ### ESLint Configuration Source: https://github.com/joshuakgoldberg/eslint-plugin-erasable-syntax-only/blob/main/_autodocs/rule-enums.md Example of how to enable the 'erasable-syntax-only/enums' rule in an ESLint configuration file. ```javascript export default defineConfig({ rules: { "erasable-syntax-only/enums": "error", }, }); ``` -------------------------------- ### Supported Import Alias Examples Source: https://github.com/joshuakgoldberg/eslint-plugin-erasable-syntax-only/blob/main/_autodocs/rule-import-aliases.md These TypeScript examples show import aliases for external modules using the require syntax, which are flagged by the rule. ```typescript import fs = require("fs"); import path = require("path"); ``` -------------------------------- ### Named Import Example - plugin Source: https://github.com/joshuakgoldberg/eslint-plugin-erasable-syntax-only/blob/main/_autodocs/api-reference.md Shows how to import the 'plugin' object specifically using a named import and configure it in an ESLint configuration object. ```javascript import { plugin } from "eslint-plugin-erasable-syntax-only"; export default defineConfig({ plugins: { "erasable-syntax-only": plugin, }, }); ``` -------------------------------- ### Recommended ESLint Configuration Source: https://github.com/joshuakgoldberg/eslint-plugin-erasable-syntax-only/blob/main/_autodocs/plugin.md Example of how to import and use the recommended configuration from the plugin in an ESLint configuration file. This enables all rules with 'error' severity. ```javascript import erasableSyntaxOnly from "eslint-plugin-erasable-syntax-only"; import { defineConfig } from "eslint/config"; export default defineConfig( eslint.configs.recommended, tseslint.configs.recommended, erasableSyntaxOnly.configs.recommended, ); ``` -------------------------------- ### Recommended Configuration Source: https://github.com/joshuakgoldberg/eslint-plugin-erasable-syntax-only/blob/main/_autodocs/api-reference.md The recommended configuration sets all four rules to error severity and can be easily integrated into your ESLint setup. ```APIDOC ## Plugin Configuration ### recommended Configuration ```typescript plugin.configs.recommended: FlatConfig ``` **Type:** ```typescript { plugins: { "erasable-syntax-only": typeof plugin; }; rules: { "erasable-syntax-only/enums": "error"; "erasable-syntax-only/import-aliases": "error"; "erasable-syntax-only/namespaces": "error"; "erasable-syntax-only/parameter-properties": "error"; }; } ``` Sets all four rules to error severity. **Usage:** ```javascript import erasableSyntaxOnly from "eslint-plugin-erasable-syntax-only"; export default defineConfig( eslint.configs.recommended, tseslint.configs.recommended, erasableSyntaxOnly.configs.recommended, ); ``` ``` -------------------------------- ### ESLint Configuration for Rules Source: https://github.com/joshuakgoldberg/eslint-plugin-erasable-syntax-only/blob/main/_autodocs/plugin.md Example of how to configure specific rules from the plugin in an ESLint configuration file. Rules are prefixed with 'erasable-syntax-only/'. ```javascript { rules: { "erasable-syntax-only/enums": "error", "erasable-syntax-only/namespaces": "warn", } } ``` -------------------------------- ### Destructured Import Example Source: https://github.com/joshuakgoldberg/eslint-plugin-erasable-syntax-only/blob/main/_autodocs/api-reference.md Illustrates importing the plugin with a specific alias using destructuring and a named import, then configuring it in an ESLint configuration object. ```javascript import { plugin as erasableSyntaxOnlyPlugin } from "eslint-plugin-erasable-syntax-only"; export default defineConfig({ plugins: { "erasable-syntax-only": erasableSyntaxOnlyPlugin, }, }); ``` -------------------------------- ### CachedFactory Usage Example Source: https://github.com/joshuakgoldberg/eslint-plugin-erasable-syntax-only/blob/main/_autodocs/types.md Demonstrates the usage of `CachedFactory` for caching computations based on `TSModuleDeclaration` nodes. The `get` method returns a cached result or computes it if not present. ```typescript const hasValueStatementCache = new CachedFactory( (node: TSESTree.TSModuleDeclaration) => { // computation... }, ); // Returns cached result or computes if not cached const result = hasValueStatementCache.get(node); ``` -------------------------------- ### TypeScript Type Inference Example Source: https://github.com/joshuakgoldberg/eslint-plugin-erasable-syntax-only/blob/main/_autodocs/api-reference.md Shows how to import and use the plugin in a TypeScript configuration file, noting that type definitions are inferred and not provided via a .d.ts file. ```typescript import erasableSyntaxOnly from "eslint-plugin-erasable-syntax-only"; const plugin = erasableSyntaxOnly; // Type: unknown (no .d.ts) export default defineConfig({ plugins: { "erasable-syntax-only": plugin, }, }); ``` -------------------------------- ### Gradual Migration: Enabling Rules Over Time Source: https://github.com/joshuakgoldberg/eslint-plugin-erasable-syntax-only/blob/main/_autodocs/index.md Demonstrates a phased approach to enabling ESLint rules for erasable syntax. Start with enums, then add import aliases, and progressively include other rules. ```javascript // Phase 1: Start with enums rules: { "erasable-syntax-only/enums": "error", } // Phase 2: Add import aliases rules: { "erasable-syntax-only/enums": "error", "erasable-syntax-only/import-aliases": "error", } // Phase 3: Continue with other rules rules: { "erasable-syntax-only/enums": "error", "erasable-syntax-only/import-aliases": "error", "erasable-syntax-only/namespaces": "error", "erasable-syntax-only/parameter-properties": "error", } ``` -------------------------------- ### Basic Namespace Declaration Source: https://github.com/joshuakgoldberg/eslint-plugin-erasable-syntax-only/blob/main/_autodocs/rule-namespaces.md A fundamental example of a TypeScript namespace declaration. ```typescript namespace NamespaceName { // Contents } ``` -------------------------------- ### Supported Syntax: Standard Constructor Parameters Source: https://github.com/joshuakgoldberg/eslint-plugin-erasable-syntax-only/blob/main/_autodocs/rule-parameter-properties.md This example demonstrates standard constructor parameters without visibility modifiers, which are not flagged by the rule. ```typescript class User { name: string; constructor( id: number, name: string ) { this.name = name; } } ``` -------------------------------- ### Violations in Usage Example Source: https://github.com/joshuakgoldberg/eslint-plugin-erasable-syntax-only/blob/main/_autodocs/rule-parameter-properties.md This example shows a class with parameter properties that will trigger ESLint violations. ```typescript class User { constructor( public id: number, protected email: string, private password: string ) {} } ``` -------------------------------- ### Pre-commit Hook Setup with Husky and Lint-staged Source: https://github.com/joshuakgoldberg/eslint-plugin-erasable-syntax-only/blob/main/_autodocs/usage-guide.md Configure husky and lint-staged to automatically run ESLint and fix issues before each commit. This ensures code quality is maintained in the repository. ```bash npx husky install npx husky add .husky/pre-commit "npx lint-staged" ``` -------------------------------- ### Allow Type-Only Namespaces Source: https://github.com/joshuakgoldberg/eslint-plugin-erasable-syntax-only/blob/main/_autodocs/index.md Shows an example of an allowed type-only namespace declaration, contrasting with a namespace containing value statements. ```typescript // ✗ Flagged (contains value statement) namespace Utils { export const MAX_LENGTH = 100; } // ✓ Allowed (type-only) namespace Types { export interface User { name: string; } } ``` -------------------------------- ### Non-Flagged Import Alias Example Source: https://github.com/joshuakgoldberg/eslint-plugin-erasable-syntax-only/blob/main/_autodocs/rule-import-aliases.md This example demonstrates an import alias that the rule will NOT flag. It references a module directly, not an external require statement. ```typescript // NOT flagged: references module directly, not external require import ns = SomeNamespace; ``` -------------------------------- ### Class Constructor Structure with Parameter Property Source: https://github.com/joshuakgoldberg/eslint-plugin-erasable-syntax-only/blob/main/_autodocs/rule-parameter-properties.md Provides an example of how parameter properties fit within a class constructor, contrasting them with regular class fields and parameters. ```typescript class Example { // Regular class field regularField: string; constructor( // Parameter property (flagged by this rule) public parameterProperty: string, // Regular parameter (not flagged) regularParameter: string ) { this.regularField = regularParameter; } } ``` -------------------------------- ### Peer Dependencies for erasable-syntax-only Source: https://github.com/joshuakgoldberg/eslint-plugin-erasable-syntax-only/blob/main/_autodocs/api-reference.md Specifies the required peer dependencies for the plugin. These must be installed in your project for the plugin to function correctly. ```json { "peerDependencies": { "@typescript-eslint/parser": ">=8", "eslint": ">=9", "typescript": ">=5" } } ``` -------------------------------- ### Gradual Migration: Enable Enums Rule Source: https://github.com/joshuakgoldberg/eslint-plugin-erasable-syntax-only/blob/main/_autodocs/usage-guide.md Start a gradual migration by enabling only the 'enums' rule in your ESLint configuration. ```javascript export default defineConfig( // ... other config ... { files: ["src/**/*.ts"], rules: { "erasable-syntax-only/enums": "error", }, }, ); ``` -------------------------------- ### TSImportEqualsDeclaration AST Node Example Source: https://github.com/joshuakgoldberg/eslint-plugin-erasable-syntax-only/blob/main/_autodocs/rule-mechanics.md Illustrates the structure of a `TSImportEqualsDeclaration` AST node, including its type, identifier, module reference, and parent properties. ```json { type: "TSImportEqualsDeclaration", id: { type: "Identifier", name: "fs" }, moduleReference: { type: "TSExternalModuleReference", expression: { type: "Literal", value: "fs" }, }, parent: /* parent node */, } ``` -------------------------------- ### Configure Rule Severity Levels Source: https://github.com/joshuakgoldberg/eslint-plugin-erasable-syntax-only/blob/main/_autodocs/configuration.md Set the severity level for each rule ('error', 'warn', 'off'). This example demonstrates setting different severities for specific rules. ```javascript export default defineConfig({ rules: { "erasable-syntax-only/enums": "error", // Fail on violation "erasable-syntax-only/import-aliases": "warn", // Warn on violation "erasable-syntax-only/namespaces": "off", // Don't check }, }); ``` -------------------------------- ### Example Violations: Namespaces with Value Statements Source: https://github.com/joshuakgoldberg/eslint-plugin-erasable-syntax-only/blob/main/_autodocs/rule-namespaces.md These examples demonstrate TypeScript namespaces that contain non-type runtime code, which will be flagged by the rule. ```typescript namespace Utils { export const MAX_LENGTH = 100; // Value statement } export namespace Config { export const apiUrl = "https://api.example.com"; // Value statement } namespace Math { export function add(a: number, b: number) { return a + b; // Value statement (function body) } } ``` -------------------------------- ### Valid Code Example: Type-Only Namespaces Source: https://github.com/joshuakgoldberg/eslint-plugin-erasable-syntax-only/blob/main/_autodocs/rule-namespaces.md Illustrates valid usage of namespaces that are strictly for type declarations, which are permitted by the rule. ```typescript namespace Types { export interface User { id: number; name: string; } } // Or convert to type-only namespace: declare namespace Utils { export const MAX_LENGTH: number; } ``` -------------------------------- ### Example Violations of Parameter Properties Source: https://github.com/joshuakgoldberg/eslint-plugin-erasable-syntax-only/blob/main/_autodocs/rule-parameter-properties.md These examples show constructor parameters with visibility modifiers (public, protected, private) or the readonly modifier, which are considered parameter properties and will be flagged by the rule. ```typescript class User { constructor( public id: number, protected name: string, private email: string ) {} } class Point { constructor( public x: number, public y: number ) {} } ``` -------------------------------- ### GitLab CI Script for ESLint Source: https://github.com/joshuakgoldberg/eslint-plugin-erasable-syntax-only/blob/main/_autodocs/usage-guide.md Configure a GitLab CI job to run ESLint on your project. This script installs dependencies and executes the linting command. ```yaml lint: image: node:20 script: - npm ci - npm run lint ``` -------------------------------- ### Accessing Rules Directly Source: https://github.com/joshuakgoldberg/eslint-plugin-erasable-syntax-only/blob/main/_autodocs/api-reference.md Get direct access to individual rules from the rules collection. ```javascript import { rules } from "eslint-plugin-erasable-syntax-only"; const enumRule = rules.enums; const importAliasRule = rules["import-aliases"]; ``` -------------------------------- ### TSEnumDeclaration AST Node Example Source: https://github.com/joshuakgoldberg/eslint-plugin-erasable-syntax-only/blob/main/_autodocs/rule-mechanics.md Illustrates the structure of a `TSEnumDeclaration` AST node, including its type, identifier, body, members, and parent/range properties. ```json { type: "TSEnumDeclaration", id: { type: "Identifier", name: "Status" }, body: { type: "TSEnumBody", members: [ { type: "TSEnumMember", id: { type: "Identifier", name: "Active" }, initializer: { type: "Literal", value: 1 }, }, // ...more members ], }, parent: /* parent node */, range: [start, end], } ``` -------------------------------- ### Combine with typescript-eslint Rules Source: https://github.com/joshuakgoldberg/eslint-plugin-erasable-syntax-only/blob/main/_autodocs/configuration.md Integrate the erasable-syntax-only plugin with existing typescript-eslint rules. This example shows how to enable rules from both plugins in your ESLint configuration. ```javascript import tseslint from "typescript-eslint"; import erasableSyntaxOnly from "eslint-plugin-erasable-syntax-only"; import { defineConfig } from "eslint/config"; export default defineConfig({ plugins: { "@typescript-eslint": tseslint.plugin, "erasable-syntax-only": erasableSyntaxOnly, }, rules: { // TypeScript ESLint rules "@typescript-eslint/no-explicit-any": "error", "@typescript-eslint/explicit-function-return-types": "error", // Erasable syntax rules "erasable-syntax-only/enums": "error", "erasable-syntax-only/import-aliases": "error", }, }); ``` -------------------------------- ### Apply Rules Selectively by File Source: https://github.com/joshuakgoldberg/eslint-plugin-erasable-syntax-only/blob/main/_autodocs/configuration.md Use the 'files' array in your ESLint configuration to apply specific rules to different sets of files. This example configures TypeScript files in 'src/' to be compliant while allowing non-erasable syntax in 'src/legacy/'. ```javascript import eslint from "@eslint/js"; import tseslint from "typescript-eslint"; import erasableSyntaxOnly from "eslint-plugin-erasable-syntax-only"; import { defineConfig } from "eslint/config"; export default defineConfig( // Global config { ignores: ["node_modules/", "dist/"], }, // TypeScript files in src/ must be erasable-syntax-only compliant { files: ["src/**/*.ts"], languageOptions: { parser: tseslint.parser, }, plugins: { "erasable-syntax-only": erasableSyntaxOnly, }, rules: { "erasable-syntax-only/enums": "error", "erasable-syntax-only/import-aliases": "error", "erasable-syntax-only/namespaces": "error", "erasable-syntax-only/parameter-properties": "error", }, }, // Legacy TypeScript files can use non-erasable syntax { files: ["src/legacy/**/*.ts"], rules: { "erasable-syntax-only/enums": "off", "erasable-syntax-only/import-aliases": "off", "erasable-syntax-only/namespaces": "off", "erasable-syntax-only/parameter-properties": "off", }, }, ); ``` -------------------------------- ### Disallowed Class Parameter Property Source: https://github.com/joshuakgoldberg/eslint-plugin-erasable-syntax-only/blob/main/docs/rules/parameter-properties.md This example demonstrates the TypeScript syntax for class parameter properties that the rule aims to prevent. ```typescript class Values { constructor(readonly value: number) {} } ``` -------------------------------- ### Example with Project-Based Type Checking Source: https://github.com/joshuakgoldberg/eslint-plugin-erasable-syntax-only/blob/main/_autodocs/configuration.md Configure ESLint to use project-based type checking by specifying the `project` and `tsconfigRootDir` options. This enables more accurate linting based on your TypeScript project structure. ```javascript export default defineConfig({ languageOptions: { parser: tseslint.parser, parserOptions: { project: "./tsconfig.json", tsconfigRootDir: "./", sourceType: "module", }, }, }); ``` -------------------------------- ### Allowed: Namespaces with Only Type Definitions Source: https://github.com/joshuakgoldberg/eslint-plugin-erasable-syntax-only/blob/main/_autodocs/rule-namespaces.md This example shows a namespace containing exclusively type definitions, which is permitted under the --erasableSyntaxOnly flag. ```typescript namespace Types { export interface User { name: string; } export type Status = "active" | "inactive"; } ``` -------------------------------- ### Manual Fix for Parameter Properties Source: https://github.com/joshuakgoldberg/eslint-plugin-erasable-syntax-only/blob/main/_autodocs/rule-parameter-properties.md This example shows how to manually fix parameter property violations by converting them to explicit class fields. ```typescript class User { public id: number; protected email: string; private password: string; constructor(id: number, email: string, password: string) { this.id = id; this.email = email; this.password = password; } } ``` -------------------------------- ### Parameter Property AST Node Example Source: https://github.com/joshuakgoldberg/eslint-plugin-erasable-syntax-only/blob/main/_autodocs/rule-parameter-properties.md This TypeScript code snippet shows the structure of the messages object used by the rule, specifically for the 'parameterProperty' message. ```typescript messages: { parameterProperty: "This parameter property will not be allowed under TypeScript's --erasableSyntaxOnly.", } ``` -------------------------------- ### TSParameterProperty AST Node Example Source: https://github.com/joshuakgoldberg/eslint-plugin-erasable-syntax-only/blob/main/_autodocs/rule-mechanics.md Represents a parameter property in a TypeScript constructor or method. It allows properties to be declared and initialized in a single place. ```typescript { type: "TSParameterProperty", modifier: "public", parameter: { type: "Identifier", name: "id", typeAnnotation: { type: "TSTypeAnnotation", typeAnnotation: { type: "TSNumberKeyword" }, }, }, parent: /* parent node */, } ``` -------------------------------- ### TSModuleDeclaration AST Node Example Source: https://github.com/joshuakgoldberg/eslint-plugin-erasable-syntax-only/blob/main/_autodocs/rule-mechanics.md Represents a TypeScript module declaration in the Abstract Syntax Tree (AST). Used to define modules within TypeScript code. ```typescript { type: "TSModuleDeclaration", id: { type: "Identifier", name: "Utils" }, body: { type: "TSModuleBlock", body: [ /* statements */ ], }, declare: false, parent: /* parent node */, } ``` -------------------------------- ### Type-Only Namespace with Interfaces and Types Source: https://github.com/joshuakgoldberg/eslint-plugin-erasable-syntax-only/blob/main/_autodocs/rule-namespaces.md An example of a type-only namespace that includes interfaces, type aliases, and nested type-only namespaces, which are correctly ignored by the rule. ```typescript namespace Types { export interface Point { x: number; y: number; } export type Direction = "up" | "down" | "left" | "right"; export namespace Nested { export interface Config { enabled: boolean; } } } ``` -------------------------------- ### Detecting Import Alias Violations Source: https://github.com/joshuakgoldberg/eslint-plugin-erasable-syntax-only/blob/main/_autodocs/rule-import-aliases.md This snippet shows examples of import alias declarations that the rule will flag. These use the `import alias = require('module')` syntax. ```typescript import fs = require("fs"); import path = require("path"); import axios = require("axios"); ``` -------------------------------- ### Cached Factory for Namespace Analysis Source: https://github.com/joshuakgoldberg/eslint-plugin-erasable-syntax-only/blob/main/_autodocs/utilities.md Example usage of `CachedFactory` from `cached-factory` to memoize expensive computations, specifically for analyzing `TSModuleDeclaration` nodes in the `namespaces` rule. This improves performance by caching analysis results. ```typescript const hasValueStatementCache = new CachedFactory( (node: TSESTree.TSModuleDeclaration) => !node.declare && node.id.type !== AST_NODE_TYPES.Literal && node.body.body.some?.(isValueStatement), ); ``` -------------------------------- ### Enable Recommended Configuration Source: https://github.com/joshuakgoldberg/eslint-plugin-erasable-syntax-only/blob/main/_autodocs/configuration.md Use the built-in recommended configuration to enable all rules with 'error' severity. This is a shorthand for manually enabling all rules. ```javascript import erasableSyntaxOnly from "eslint-plugin-erasable-syntax-only"; import { defineConfig } from "eslint/config"; export default defineConfig( erasableSyntaxOnly.configs.recommended, ); ``` ```javascript export default defineConfig({ plugins: { "erasable-syntax-only": erasableSyntaxOnly, }, rules: { "erasable-syntax-only/enums": "error", "erasable-syntax-only/import-aliases": "error", "erasable-syntax-only/namespaces": "error", "erasable-syntax-only/parameter-properties": "error", }, }); ``` -------------------------------- ### Run ESLint Source: https://github.com/joshuakgoldberg/eslint-plugin-erasable-syntax-only/blob/main/_autodocs/usage-guide.md Execute ESLint on the source directory to check for violations. ```bash npx eslint src/ ``` -------------------------------- ### Project Structure Source: https://github.com/joshuakgoldberg/eslint-plugin-erasable-syntax-only/blob/main/_autodocs/README.md Overview of the plugin's source code directory structure. ```text src/ ├── index.ts # Main plugin export ├── types.ts # Type definitions ├── utils.ts # createRule utility └── rules/ ├── index.ts # Rules collection ├── enums.ts # Enum detection rule ├── import-aliases.ts # Import alias detection rule ├── namespaces.ts # Namespace detection rule └── parameter-properties.ts # Parameter property detection rule ``` -------------------------------- ### Fix Enum Violation (Auto-fixable) Source: https://github.com/joshuakgoldberg/eslint-plugin-erasable-syntax-only/blob/main/_autodocs/usage-guide.md Example of an enum violation and its auto-fixable TypeScript code. ```typescript enum Status { Active = 1, Inactive = 2, } ``` ```typescript const Status = { Active: 1, Inactive: 2, } as const; type Status = typeof Status[keyof typeof Status]; ``` -------------------------------- ### Recommended package.json Scripts for Linting and Testing Source: https://github.com/joshuakgoldberg/eslint-plugin-erasable-syntax-only/blob/main/_autodocs/usage-guide.md A collection of useful npm scripts for linting, fixing linting issues, checking for maximum warnings, type checking, and running tests. These scripts streamline the development workflow. ```json { "scripts": { "lint": "eslint .", "lint:fix": "eslint . --fix", "lint:check": "eslint . --max-warnings 0", "type-check": "tsc --noEmit", "test": "vitest" } } ``` -------------------------------- ### Lint Files with ESLint Source: https://github.com/joshuakgoldberg/eslint-plugin-erasable-syntax-only/blob/main/_autodocs/index.md Command to lint all project files using ESLint. ```bash npm run lint # Lint all files with ESLint ``` -------------------------------- ### Fix Import Alias Violation (Namespace Import) Source: https://github.com/joshuakgoldberg/eslint-plugin-erasable-syntax-only/blob/main/_autodocs/usage-guide.md Example of fixing an import alias violation using namespace imports. ```typescript import fs = require("fs"); import path = require("path"); ``` ```typescript import * as fs from "fs"; import * as path from "path"; ``` -------------------------------- ### ESLint Configuration for Parameter Properties Rule Source: https://github.com/joshuakgoldberg/eslint-plugin-erasable-syntax-only/blob/main/_autodocs/api-reference.md Shows how to enable the 'parameter-properties' rule in an ESLint configuration file with 'error' severity. ```javascript rules: { "erasable-syntax-only/parameter-properties": "error", } ``` -------------------------------- ### Fix Import Alias Violation (Default Import) Source: https://github.com/joshuakgoldberg/eslint-plugin-erasable-syntax-only/blob/main/_autodocs/usage-guide.md Example of fixing an import alias violation using default imports. ```typescript import fs = require("fs"); import path = require("path"); ``` ```typescript import fs from "fs"; import path from "path"; ``` -------------------------------- ### Rule Options Schema and Default Options Source: https://github.com/joshuakgoldberg/eslint-plugin-erasable-syntax-only/blob/main/_autodocs/api-reference.md Illustrates the common structure for rule options, showing that 'parameter-properties' and other rules have no configuration options beyond enabling/disabling and severity. ```typescript defaultOptions: [] schema: [] ``` -------------------------------- ### Migrate from Legacy .eslintrc.json to Flat Config Source: https://github.com/joshuakgoldberg/eslint-plugin-erasable-syntax-only/blob/main/_autodocs/configuration.md Shows the conversion of a rule configuration from the old .eslintrc.json format to the new Flat Config format using an ESLint configuration file. ```json { "plugins": ["erasable-syntax-only"], "rules": { "erasable-syntax-only/enums": "error" } } ``` ```javascript import erasableSyntaxOnly from "eslint-plugin-erasable-syntax-only"; export default [{ plugins: { "erasable-syntax-only": erasableSyntaxOnly, }, rules: { "erasable-syntax-only/enums": "error", }, }]; ``` -------------------------------- ### File-Based Overrides for Selective Rule Application Source: https://github.com/joshuakgoldberg/eslint-plugin-erasable-syntax-only/blob/main/_autodocs/index.md Shows how to use ESLint's file configuration to apply specific rules to different sets of files. This allows for granular control over rule enforcement based on file paths. ```javascript { files: ["src/modern/**/*.ts"], rules: { "erasable-syntax-only/enums": "error", }, }, { files: ["src/legacy/**/*.ts"], rules: { "erasable-syntax-only/enums": "off", }, } ``` -------------------------------- ### ESLint Rule Creation Pattern Source: https://github.com/joshuakgoldberg/eslint-plugin-erasable-syntax-only/blob/main/_autodocs/rule-mechanics.md Demonstrates the standard structure for creating ESLint rules using the `createRule` utility. This pattern includes defining the rule's name, its creation logic, default options, and metadata. ```typescript export const rule = createRule({ name: "rule-name", create(context) { return { VisitorMethodName(node) { context.report({ messageId: "messageKey", node, suggest: [ /* optional */ ], }); }, }; }, defaultOptions: [], meta: { docs: { description: "Rule description", }, hasSuggestions: boolean, messages: { messageKey: "Message text", }, schema: [], type: "problem", }, }); ``` -------------------------------- ### Configure ESLint with Plugin Source: https://github.com/joshuakgoldberg/eslint-plugin-erasable-syntax-only/blob/main/README.md Add the plugin to your ESLint configuration and extend its recommended rules. ```typescript import eslint from "@eslint/js"; import erasableSyntaxOnly from "eslint-plugin-erasable-syntax-only"; import { defineConfig } from "eslint/config"; export default defineConfig( eslint.configs.recommended, tseslint.configs.recommended, erasableSyntaxOnly.configs.recommended, // 👈 ); ``` -------------------------------- ### Plugin Registration in ESLint Config Source: https://github.com/joshuakgoldberg/eslint-plugin-erasable-syntax-only/blob/main/_autodocs/plugin.md Demonstrates how to register the plugin and enable its rules within an ESLint configuration file. The plugin is added to the 'plugins' section and rules are referenced with a prefix. ```javascript import erasableSyntaxOnly from "eslint-plugin-erasable-syntax-only"; export default defineConfig({ plugins: { "erasable-syntax-only": erasableSyntaxOnly, }, rules: { "erasable-syntax-only/enums": "error", }, }); ``` -------------------------------- ### GreetOptions Interface Source: https://github.com/joshuakgoldberg/eslint-plugin-erasable-syntax-only/blob/main/_autodocs/types.md Defines the structure for options used in a greeting function. It includes an optional logger, a required message, and an optional number of times to repeat the message. ```typescript export interface GreetOptions { logger?: (message: string) => void; message: string; times?: number; } ``` -------------------------------- ### File Statistics Summary Source: https://github.com/joshuakgoldberg/eslint-plugin-erasable-syntax-only/blob/main/_autodocs/README.md Provides a quick overview of the documentation files, including total count, largest files, and average size. ```text Total Documentation: 12 files, ~4000 lines Largest files: rule-mechanics.md (551), api-reference.md (508), usage-guide.md (504) Average file size: ~330 lines ``` -------------------------------- ### Violation Example: Namespace with Value Statement Source: https://github.com/joshuakgoldberg/eslint-plugin-erasable-syntax-only/blob/main/_autodocs/rule-namespaces.md This snippet demonstrates a violation where a namespace contains an exported constant, which is incompatible with the erasable syntax-only option. ```typescript namespace Utils { export const MAX_LENGTH = 100; // ✗ Violation } ``` -------------------------------- ### Generate Rule Documentation Source: https://github.com/joshuakgoldberg/eslint-plugin-erasable-syntax-only/blob/main/_autodocs/index.md Command to generate rule documentation using eslint-doc-generator. ```bash npm run build:docs # Generate rule documentation with eslint-doc-generator ``` -------------------------------- ### Importing the Plugin Source: https://github.com/joshuakgoldberg/eslint-plugin-erasable-syntax-only/blob/main/_autodocs/api-reference.md Import the plugin using its package name for use in ESLint configurations. ```javascript import erasableSyntaxOnly from "eslint-plugin-erasable-syntax-only"; // erasableSyntaxOnly is the plugin object ``` -------------------------------- ### Enum Violations Source: https://github.com/joshuakgoldberg/eslint-plugin-erasable-syntax-only/blob/main/_autodocs/rule-enums.md These examples demonstrate TypeScript enum declarations that violate the rule. They include named, exported, numeric, string, and mixed-type enums. ```typescript enum Status { Active = 1, Inactive = 2, } export enum Direction { Up = "up", Down = "down", } ``` -------------------------------- ### Gradual Migration: Add Namespaces Rule Source: https://github.com/joshuakgoldberg/eslint-plugin-erasable-syntax-only/blob/main/_autodocs/usage-guide.md Continue the migration by adding the 'namespaces' rule. Note that this rule may require manual code conversion. ```javascript export default defineConfig( // ... other config ... { files: ["src/**/*.ts"], rules: { "erasable-syntax-only/enums": "error", "erasable-syntax-only/import-aliases": "error", "erasable-syntax-only/namespaces": "error", }, }, ); ``` -------------------------------- ### Import Paths in Compiled Output Source: https://github.com/joshuakgoldberg/eslint-plugin-erasable-syntax-only/blob/main/_autodocs/api-reference.md Demonstrates the import paths used in the compiled output of the plugin, which include '.js' extensions for ES module compatibility. ```javascript import { rules } from "./rules/index.js"; import { createRule } from "../utils.js"; ``` -------------------------------- ### Run Tests with Vitest Source: https://github.com/joshuakgoldberg/eslint-plugin-erasable-syntax-only/blob/main/_autodocs/index.md Command to execute all tests using the Vitest test runner. ```bash npm test # Run tests with vitest ``` -------------------------------- ### Gradual Migration: Add Parameter Properties Rule Source: https://github.com/joshuakgoldberg/eslint-plugin-erasable-syntax-only/blob/main/_autodocs/usage-guide.md Complete the migration by adding the 'parameter-properties' rule. This rule also requires manual code conversion. ```javascript export default defineConfig( // ... other config ... { files: ["src/**/*.ts"], rules: { "erasable-syntax-only/enums": "error", "erasable-syntax-only/import-aliases": "error", "erasable-syntax-only/namespaces": "error", "erasable-syntax-only/parameter-properties": "error", }, }, ); ``` -------------------------------- ### Basic ESLint Configuration Source: https://github.com/joshuakgoldberg/eslint-plugin-erasable-syntax-only/blob/main/_autodocs/index.md Enables all four rules from the plugin with 'error' severity by extending recommended configurations. ```javascript import eslint from "@eslint/js"; import tseslint from "typescript-eslint"; import erasableSyntaxOnly from "eslint-plugin-erasable-syntax-only"; import { defineConfig } from "eslint/config"; export default defineConfig( eslint.configs.recommended, tseslint.configs.recommended, erasableSyntaxOnly.configs.recommended, ); ``` -------------------------------- ### Basic ESLint Configuration Source: https://github.com/joshuakgoldberg/eslint-plugin-erasable-syntax-only/blob/main/_autodocs/usage-guide.md Configure ESLint to use the erasable-syntax-only plugin and enable its rules for TypeScript files. ```javascript import eslint from "@eslint/js"; import tseslint from "typescript-eslint"; import erasableSyntaxOnly from "eslint-plugin-erasable-syntax-only"; import { defineConfig } from "eslint/config"; export default defineConfig( { ignores: ["dist/", "node_modules/", "**/*.config.js"], }, eslint.configs.recommended, tseslint.configs.recommended, { files: ["**/*.ts"], languageOptions: { parser: tseslint.parser, parserOptions: { project: "./tsconfig.json", }, }, plugins: { "erasable-syntax-only": erasableSyntaxOnly, }, rules: { "erasable-syntax-only/enums": "error", "erasable-syntax-only/import-aliases": "error", "erasable-syntax-only/namespaces": "error", "erasable-syntax-only/parameter-properties": "error", }, }, ); ``` -------------------------------- ### Create ESLint Rule with Documentation URL Source: https://github.com/joshuakgoldberg/eslint-plugin-erasable-syntax-only/blob/main/_autodocs/utilities.md Use this factory function to create ESLint rules. It automatically generates documentation URLs based on the rule name, simplifying rule creation and linking to documentation. ```typescript const createRule = ESLintUtils.RuleCreator( (name) => `https://github.com/JoshuaKGoldberg/eslint-plugin-erasable-syntax-only/blob/main/docs/rules/${name}.md`, ); ``` ```typescript export const rule = createRule({ name: "rule-name", meta: { /* ... */ }, create(context) { /* ... */ }, defaultOptions: [], }); ``` ```typescript import { createRule } from "../utils.js"; ``` ```typescript (name) => `https://github.com/JoshuaKGoldberg/eslint-plugin-erasable-syntax-only/blob/main/docs/rules/${name}.md` ``` -------------------------------- ### TypeScript Compiler Error Example Source: https://github.com/joshuakgoldberg/eslint-plugin-erasable-syntax-only/blob/main/_autodocs/configuration.md Illustrates a TypeScript compiler error when 'erasableSyntaxOnly' is true and the ESLint rule is disabled. This highlights the importance of aligning TypeScript and ESLint configurations. ```typescript // TypeScript will error: // "This would be erased at runtime." enum Status { Active } // ESLint will NOT flag it (rule is off) ``` -------------------------------- ### GitHub Actions Workflow for ESLint Source: https://github.com/joshuakgoldberg/eslint-plugin-erasable-syntax-only/blob/main/_autodocs/usage-guide.md Set up a GitHub Actions workflow to run ESLint on every push and pull request. This automates linting checks in your CI/CD pipeline. ```yaml name: ESLint on: [push, pull_request] jobs: lint: runs-on: ubuntu-latest steps: - uses: actions/checkout@v3 - uses: actions/setup-node@v3 with: node-version: 20 - run: npm ci - run: npm run lint ``` -------------------------------- ### Development Workflow Commands Source: https://github.com/joshuakgoldberg/eslint-plugin-erasable-syntax-only/blob/main/_autodocs/usage-guide.md Execute common development tasks using npm scripts: check for linting violations, automatically fix them, perform type checking, and run tests. These commands facilitate a robust development process. ```bash # Check for violations npm run lint # Fix auto-fixable violations npm run lint:fix # Type check before commit npm run type-check # Run tests npm test ``` -------------------------------- ### Extract Package Name and Version Source: https://github.com/joshuakgoldberg/eslint-plugin-erasable-syntax-only/blob/main/_autodocs/utilities.md Reads the package name and version from `package.json` to populate the plugin's `meta` object. Uses `require()` instead of `import()` to properly resolve the package root relative to the compiled output directory. ```typescript const require = Module.createRequire(import.meta.url); const { name, version } = // `import`ing here would bypass the TSConfig's `"rootDir": "src"` require("../package.json") as typeof import("../package.json"); ``` -------------------------------- ### Validate ESLint Configuration Source: https://github.com/joshuakgoldberg/eslint-plugin-erasable-syntax-only/blob/main/_autodocs/configuration.md Provides commands to validate your ESLint configuration for syntax errors and to run ESLint on a test file. ```bash # Check for syntax errors in config npx eslint --inspect-config # Run ESLint on a test file npx eslint src/test.ts ``` -------------------------------- ### Simple Public Properties Source: https://github.com/joshuakgoldberg/eslint-plugin-erasable-syntax-only/blob/main/_autodocs/rule-parameter-properties.md Demonstrates converting a class with simple public parameter properties into explicit field declarations. ```typescript class Point { constructor(public x: number, public y: number) {} } ``` ```typescript class Point { public x: number; public y: number; constructor(x: number, y: number) { this.x = x; this.y = y; } } ``` -------------------------------- ### Apply ESLint Fixes Source: https://github.com/joshuakgoldberg/eslint-plugin-erasable-syntax-only/blob/main/_autodocs/usage-guide.md Run ESLint with the --fix flag to automatically apply suggested fixes for auto-fixable rules. ```bash npx eslint src/ --fix ``` -------------------------------- ### Validate Generated Documentation Source: https://github.com/joshuakgoldberg/eslint-plugin-erasable-syntax-only/blob/main/_autodocs/index.md Command to validate the generated documentation files using ESLint. ```bash npm run lint:docs # Validate generated documentation ``` -------------------------------- ### Selective Rule Configuration Source: https://github.com/joshuakgoldberg/eslint-plugin-erasable-syntax-only/blob/main/_autodocs/index.md Configures individual rules from the plugin with specific severity levels. ```javascript export default defineConfig({ plugins: { "erasable-syntax-only": erasableSyntaxOnly, }, rules: { "erasable-syntax-only/enums": "error", "erasable-syntax-only/import-aliases": "warn", "erasable-syntax-only/namespaces": "off", "erasable-syntax-only/parameter-properties": "error", }, }); ``` -------------------------------- ### Documentation URL Pattern Source: https://github.com/joshuakgoldberg/eslint-plugin-erasable-syntax-only/blob/main/_autodocs/api-reference.md The pattern used to automatically generate documentation URLs for rules. This format is utilized by tools like eslint-doc-generator. ```text https://github.com/JoshuaKGoldberg/eslint-plugin-erasable-syntax-only/blob/main/docs/rules/{ruleName}.md ``` -------------------------------- ### ES Module Export Syntax Source: https://github.com/joshuakgoldberg/eslint-plugin-erasable-syntax-only/blob/main/_autodocs/api-reference.md Illustrates the ES module export syntax used by the plugin, including named exports for 'plugin' and 'rules', and a default export for the plugin itself. ```typescript export const plugin = { /* ... */ }; export default plugin; export { rules }; ``` -------------------------------- ### File-Based Exemptions for Legacy Code Source: https://github.com/joshuakgoldberg/eslint-plugin-erasable-syntax-only/blob/main/_autodocs/usage-guide.md Configure ESLint to apply rules to new code while exempting specific legacy directories. ```javascript export default defineConfig( // New code must be erasable-syntax-only compliant { files: ["src/**/*.ts", "!src/legacy/**"], rules: { "erasable-syntax-only/enums": "error", "erasable-syntax-only/import-aliases": "error", "erasable-syntax-only/namespaces": "error", "erasable-syntax-only/parameter-properties": "error", }, }, // Legacy code: rules disabled { files: ["src/legacy/**/*.ts"], rules: { "erasable-syntax-only/enums": "off", "erasable-syntax-only/import-aliases": "off", "erasable-syntax-only/namespaces": "off", "erasable-syntax-only/parameter-properties": "off", }, }, ); ``` -------------------------------- ### AST Node Visitor Pattern Source: https://github.com/joshuakgoldberg/eslint-plugin-erasable-syntax-only/blob/main/_autodocs/rule-mechanics.md Illustrates the visitor pattern used by ESLint rules to interact with the Abstract Syntax Tree (AST). Rules return an object with methods named after AST node types to process specific nodes. ```typescript { TSEnumDeclaration(node) { /* runs when enum is encountered */ }, TSImportEqualsDeclaration(node) { /* runs when import = is encountered */ }, } ``` -------------------------------- ### Plugin Export Object Source: https://github.com/joshuakgoldberg/eslint-plugin-erasable-syntax-only/blob/main/_autodocs/index.md The main plugin object exports configurations, metadata, and all available rules. ```typescript export const plugin = { configs: { get recommended() { /* ... */ } }, meta: { name: "eslint-plugin-erasable-syntax-only", version: "0.4.1" }, rules: { enums, "import-aliases": importAliases, namespaces, "parameter-properties": parameterProperties, }, }; export default plugin; export { rules }; ``` -------------------------------- ### ESLint Configuration for Import Aliases Rule Source: https://github.com/joshuakgoldberg/eslint-plugin-erasable-syntax-only/blob/main/_autodocs/rule-import-aliases.md This JavaScript snippet shows how to enable the `erasable-syntax-only/import-aliases` rule in your ESLint configuration. ```javascript export default defineConfig({ rules: { "erasable-syntax-only/import-aliases": "error", }, }); ``` -------------------------------- ### Conflict Resolution with Overlapping Rules Source: https://github.com/joshuakgoldberg/eslint-plugin-erasable-syntax-only/blob/main/_autodocs/configuration.md Demonstrates how ESLint resolves rule conflicts when configurations overlap. The last matching configuration takes precedence. ```javascript export default defineConfig( { // Config 1: Apply to all TypeScript files files: ["**/*.ts"], rules: { "erasable-syntax-only/enums": "error", }, }, { // Config 2: Override for legacy files (applied after Config 1) files: ["src/legacy/**/*.ts"], rules: { "erasable-syntax-only/enums": "off", }, }, ); // Result: Legacy files have the rule disabled despite the earlier configuration. ``` -------------------------------- ### Skip Module Parent Helper Source: https://github.com/joshuakgoldberg/eslint-plugin-erasable-syntax-only/blob/main/_autodocs/rule-mechanics.md Navigates from a namespace node to its parent namespace if nested. This is useful for analyzing nested namespace structures. ```typescript function skipModuleParent(node) { return node.parent.type === AST_NODE_TYPES.TSModuleDeclaration ? node.parent : node; } ``` -------------------------------- ### Convert Import Alias to Default or Namespace Import Source: https://github.com/joshuakgoldberg/eslint-plugin-erasable-syntax-only/blob/main/_autodocs/index.md Demonstrates converting a TypeScript import alias for an external module to either a default import or a namespace import. ```typescript // ✗ Flagged import fs = require("fs"); // ✓ Suggestion 1: Default import import fs from "fs"; // ✓ Suggestion 2: Namespace import import * as fs from "fs"; ``` -------------------------------- ### Import Aliases Rule Configuration Source: https://github.com/joshuakgoldberg/eslint-plugin-erasable-syntax-only/blob/main/_autodocs/api-reference.md Configure the 'import-aliases' rule to 'error' severity in your ESLint configuration. ```javascript rules: { "erasable-syntax-only/import-aliases": "error", } ``` -------------------------------- ### Allow Standard ES Module Imports Source: https://github.com/joshuakgoldberg/eslint-plugin-erasable-syntax-only/blob/main/docs/rules/import-aliases.md These snippets show valid alternatives to TypeScript's import aliases, using standard ES module import patterns. ```typescript import values from "values"; ``` ```typescript import * as values from "values"; ``` -------------------------------- ### ESLint Rule Severity Levels Source: https://github.com/joshuakgoldberg/eslint-plugin-erasable-syntax-only/blob/main/_autodocs/api-reference.md Demonstrates the different severity levels for ESLint rules, including 'error', 'warn', and 'off', and their corresponding numeric values. ```javascript "erasable-syntax-only/enums": "error" // Fail lint checks "erasable-syntax-only/enums": "warn" // Warn only "erasable-syntax-only/enums": "off" // Disabled "erasable-syntax-only/enums": 2 // Same as "error" "erasable-syntax-only/enums": 1 // Same as "warn" "erasable-syntax-only/enums": 0 // Same as "off" ``` -------------------------------- ### ESLint Configuration for Parameter Properties Rule Source: https://github.com/joshuakgoldberg/eslint-plugin-erasable-syntax-only/blob/main/_autodocs/rule-parameter-properties.md This is how you would enable the 'erasable-syntax-only/parameter-properties' rule in your ESLint configuration. ```javascript export default defineConfig({ rules: { "erasable-syntax-only/parameter-properties": "error", }, }); ``` -------------------------------- ### Configure TypeScript ESLint Parser Source: https://github.com/joshuakgoldberg/eslint-plugin-erasable-syntax-only/blob/main/_autodocs/configuration.md This plugin requires the TypeScript ESLint parser. Ensure it is imported and configured correctly in your ESLint configuration. ```javascript import tseslint from "typescript-eslint"; import { defineConfig } from "eslint/config"; export default defineConfig({ languageOptions: { parser: tseslint.parser, parserOptions: { project: "./tsconfig.json", sourceType: "module", }, }, }); ``` -------------------------------- ### Namespaces Rule Configuration Source: https://github.com/joshuakgoldberg/eslint-plugin-erasable-syntax-only/blob/main/_autodocs/api-reference.md Configure the 'namespaces' rule to 'error' severity in your ESLint configuration. ```javascript rules: { "erasable-syntax-only/namespaces": "error", } ``` -------------------------------- ### Rule Registry Export Source: https://github.com/joshuakgoldberg/eslint-plugin-erasable-syntax-only/blob/main/_autodocs/index.md Exports all four rules as a single collection. ```typescript export const rules = { enums, "import-aliases": importAliases, namespaces, "parameter-properties": parameterProperties, }; ``` -------------------------------- ### Type Check with TypeScript Source: https://github.com/joshuakgoldberg/eslint-plugin-erasable-syntax-only/blob/main/_autodocs/index.md Command to perform a type check on the project using the TypeScript compiler. ```bash npm run tsc # Type check with TypeScript ``` -------------------------------- ### Plugin Metadata Source: https://github.com/joshuakgoldberg/eslint-plugin-erasable-syntax-only/blob/main/_autodocs/api-reference.md Access metadata about the plugin, including its name and version. ```APIDOC ## Plugin Metadata ### plugin.meta.name ```typescript type: string value: "eslint-plugin-erasable-syntax-only" ``` ### plugin.meta.version ```typescript type: string value: from package.json (e.g., "0.4.1") ``` Read at runtime from `package.json`. ``` -------------------------------- ### Compile TypeScript with tsdown Source: https://github.com/joshuakgoldberg/eslint-plugin-erasable-syntax-only/blob/main/_autodocs/index.md Command to compile TypeScript source files into JavaScript output using tsdown. ```bash npm run build # Compile TypeScript with tsdown ``` -------------------------------- ### Parameter Property Transformation to JavaScript Source: https://github.com/joshuakgoldberg/eslint-plugin-erasable-syntax-only/blob/main/_autodocs/rule-parameter-properties.md Explains why parameter properties are non-erasable by showing their transformation into runtime JavaScript code, which involves explicit field assignments. ```typescript constructor(public id: number) {} ``` ```javascript constructor(id) { this.id = id; } ``` -------------------------------- ### Mixed Visibility Parameter Properties Source: https://github.com/joshuakgoldberg/eslint-plugin-erasable-syntax-only/blob/main/_autodocs/rule-parameter-properties.md Shows how to convert a class with mixed visibility parameter properties (public, protected, private) into explicit field declarations. ```typescript class Config { constructor( public appName: string, protected version: string, private apiKey: string ) {} } ``` ```typescript class Config { public appName: string; protected version: string; private apiKey: string; constructor( appName: string, version: string, apiKey: string ) { this.appName = appName; this.version = version; this.apiKey = apiKey; } } ``` -------------------------------- ### Parameter Properties Rule Definition Source: https://github.com/joshuakgoldberg/eslint-plugin-erasable-syntax-only/blob/main/_autodocs/api-reference.md Defines the 'parameter-properties' ESLint rule, specifying its creation function, default options, metadata including documentation, messages, schema, and type. ```typescript { create: (context: RuleContext) => RuleListener; defaultOptions: []; meta: { docs: { description: "Avoid using TypeScript's class parameter properties."; }; hasSuggestions: false; messages: { parameterProperty: "This parameter property will not be allowed under TypeScript's --erasableSyntaxOnly."; }; schema: []; type: "problem"; }; name: "parameter-properties"; } ``` -------------------------------- ### Converting Import Alias to Namespace Import Source: https://github.com/joshuakgoldberg/eslint-plugin-erasable-syntax-only/blob/main/_autodocs/rule-import-aliases.md This snippet illustrates converting an import alias to an ES6 namespace (wildcard) import. This is useful for importing the entire module namespace. ```typescript import * as axios from "axios"; ``` -------------------------------- ### Configure ESLint to Use Namespaces Rule Source: https://github.com/joshuakgoldberg/eslint-plugin-erasable-syntax-only/blob/main/_autodocs/rule-namespaces.md Add the 'erasable-syntax-only/namespaces' rule to your ESLint configuration to enable checks for namespace declarations. ```javascript export default defineConfig({ rules: { "erasable-syntax-only/namespaces": "error", }, }); ``` -------------------------------- ### Parameter Properties with Readonly Source: https://github.com/joshuakgoldberg/eslint-plugin-erasable-syntax-only/blob/main/_autodocs/rule-parameter-properties.md Illustrates converting a class with readonly public parameter properties into explicit readonly field declarations. ```typescript class User { constructor(public readonly id: number, public readonly email: string) {} } ``` ```typescript class User { public readonly id: number; public readonly email: string; constructor(id: number, email: string) { this.id = id; this.email = email; } } ``` -------------------------------- ### Optional Property Access and Type Guards for Null Safety Source: https://github.com/joshuakgoldberg/eslint-plugin-erasable-syntax-only/blob/main/_autodocs/rule-mechanics.md Demonstrates handling potential null or undefined values using optional chaining and type guards. Useful for robust error handling in TypeScript. ```typescript // Optional property access node.body.body?.some?.(isValueStatement) // Type guards enumMember.id.type === AST_NODE_TYPES.Identifier ? enumMember.id.name : enumMember.id.value ``` -------------------------------- ### ESLint SuggestDescriptor Interface Source: https://github.com/joshuakgoldberg/eslint-plugin-erasable-syntax-only/blob/main/_autodocs/types.md Defines the structure for a suggestion provided to `context.report()`. It includes a message ID and a fix function. ```typescript interface SuggestDescriptor { messageId: string; fix(fixer: RuleFixer): Fix | Fix[]; } ``` -------------------------------- ### Plugin Exports Source: https://github.com/joshuakgoldberg/eslint-plugin-erasable-syntax-only/blob/main/_autodocs/api-reference.md The main plugin object and the rules collection are exported from the package. The plugin object is also the default export for convenient importing. ```APIDOC ## Package Exports ### Default Export ```typescript export default plugin ``` The plugin object is also the default export for convenient importing. ```javascript import erasableSyntaxOnly from "eslint-plugin-erasable-syntax-only"; // erasableSyntaxOnly is the plugin object ``` ### Named Exports ```typescript export const plugin: PluginExport export const rules: RulesCollection ``` #### `plugin` The main plugin object containing all configuration and rules. **Type:** ```typescript { configs: { recommended: FlatConfig; }; meta: { name: string; version: string; }; rules: RulesCollection; } ``` **Example:** ```javascript import { plugin } from "eslint-plugin-erasable-syntax-only"; export default { plugins: { "erasable-syntax-only": plugin, }, }; ``` #### `rules` Direct access to the rules collection without the plugin object. **Type:** ```typescript { enums: RuleModule; "import-aliases": RuleModule; namespaces: RuleModule; "parameter-properties": RuleModule; } ``` **Example:** ```javascript import { rules } from "eslint-plugin-erasable-syntax-only"; const enumRule = rules.enums; const importAliasRule = rules["import-aliases"]; ``` ``` -------------------------------- ### Conditional Fix Suggestion for Fallback Behavior Source: https://github.com/joshuakgoldberg/eslint-plugin-erasable-syntax-only/blob/main/_autodocs/rule-mechanics.md Shows how to conditionally provide a fix suggestion based on whether a fix can be generated. If not, the suggestion is null, indicating no fix is offered. ```typescript suggest: canSuggestion ? [ { fix: ... } ] : null ```