### Install TSSLint Configuration Package Source: https://github.com/johnsoncodehk/tsslint/blob/master/packages/vscode/README.md Install the required configuration package as a development dependency in your project. ```bash npm install @tsslint/config --save-dev ``` -------------------------------- ### Install TSL package Source: https://github.com/johnsoncodehk/tsslint/blob/master/README.md Install the TSL package as a development dependency. ```bash npm install tsl --save-dev ``` -------------------------------- ### Installing TSSLint ESLint Compatibility Package Source: https://github.com/johnsoncodehk/tsslint/blob/master/README.md Install the `@tsslint/compat-eslint` package to enable TSSLint to use ESLint rules. Optionally install `eslint` if you need to use ESLint's built-in rules. ```bash npm install @tsslint/compat-eslint --save-dev ``` ```bash npm install eslint --save-dev ``` -------------------------------- ### VSCode Extension Setup Source: https://context7.com/johnsoncodehk/tsslint/llms.txt Add the TSSLint extension to your VSCode recommendations. ```json // .vscode/extensions.json { "recommendations": [ "johnsoncodehk.vscode-tsslint" ] } ``` -------------------------------- ### Installing TSLint Compatibility Package Source: https://github.com/johnsoncodehk/tsslint/blob/master/README.md Install the `tslint` package if you intend to use TSLint's built-in rules within TSSLint. ```bash npm install tslint --save-dev ``` -------------------------------- ### Minimal TSSLint Configuration Source: https://github.com/johnsoncodehk/tsslint/blob/master/README.md Define a minimal TSSLint configuration file. This serves as a basic setup for custom rules. ```typescript import { defineConfig } from '@tsslint/config'; export default defineConfig({ rules: { // Define or import your rules here }, }); ``` -------------------------------- ### Define a React Component Source: https://github.com/johnsoncodehk/tsslint/blob/master/fixtures/meta-frameworks/fixture.mdx Defines a functional React component named 'Component' that logs a message to the console. No specific setup or imports are required for this basic example. ```javascript export function Component() { console.log('Hello, world!'); } ``` -------------------------------- ### Updating Type Definitions for ESLint Compatibility Source: https://github.com/johnsoncodehk/tsslint/blob/master/README.md Run `npx tsslint-docgen` after installing ESLint to update JSDoc for built-in rules, improving IDE support. ```bash npx tsslint-docgen ``` -------------------------------- ### TSSLint Rule Example: No Debugger Statement Source: https://github.com/johnsoncodehk/tsslint/blob/master/README.md An example of a custom TSSLint rule that reports a diagnostic if a debugger statement is found in the code. It uses the TypeScript AST to traverse the file. ```typescript // rules/no-debugger.ts import { defineRule } from '@tsslint/config'; export default defineRule(({ typescript: ts, file, report }) => { ts.forEachChild(file, function cb(node) { if (node.kind === ts.SyntaxKind.DebuggerStatement) { report( 'Debugger statement is not allowed.', node.getStart(file), node.getEnd() ); } ts.forEachChild(node, cb); }); }); ``` -------------------------------- ### CLI Framework-Specific Commands Source: https://context7.com/johnsoncodehk/tsslint/llms.txt Use specific flags to lint files from meta-frameworks like Vue, MDX, and Astro. ```bash # Lint Vue Single-File Components npx tsslint --vue-project tsconfig.json # Lint MDX files npx tsslint --mdx-project tsconfig.json # Lint Astro components npx tsslint --astro-project tsconfig.json # Lint Vue Vine files npx tsslint --vue-vine-project tsconfig.json # Lint TS Macro files npx tsslint --ts-macro-project tsconfig.json # Combine multiple framework types npx tsslint \ --project packages/*/tsconfig.json \ --vue-project apps/web/tsconfig.json \ --mdx-project docs/tsconfig.json ``` -------------------------------- ### CLI Usage Source: https://context7.com/johnsoncodehk/tsslint/llms.txt Command line interface commands for linting projects and framework-specific files. ```APIDOC ## CLI Commands ### Description Run TSSLint from the command line for CI/CD and build processes. ### Commands - `npx tsslint --project `: Lint a single project. - `--fix`: Lint and auto-fix violations. - `--filter `: Filter files to lint. - `--force`: Force re-lint without cache. ### Framework-Specific Flags - `--vue-project`: Lint Vue Single-File Components. - `--mdx-project`: Lint MDX files. - `--astro-project`: Lint Astro components. - `--vue-vine-project`: Lint Vue Vine files. - `--ts-macro-project`: Lint TS Macro files. ``` -------------------------------- ### Configuration Utilities Source: https://context7.com/johnsoncodehk/tsslint/llms.txt Functions for importing and defining linting rules from various sources. ```APIDOC ## importESLintRules ### Description Imports and converts ESLint rules (core and plugins) to TSSLint format. ### Usage ```typescript import { defineConfig, importESLintRules } from '@tsslint/config'; export default defineConfig({ rules: await importESLintRules({ ... }) }); ``` ## importTSLintRules ### Description Imports and converts legacy TSLint rules to TSSLint format. ### Usage ```typescript import { defineConfig, importTSLintRules } from '@tsslint/config'; export default defineConfig({ rules: await importTSLintRules({ ... }) }); ``` ## fromTSLRules ### Description Imports and converts TSL (TypeScript Linter) rules to TSSLint format. ### Usage ```typescript import { defineConfig, fromTSLRules } from '@tsslint/config'; import { core } from 'tsl'; export default defineConfig({ rules: fromTSLRules(core.all()) }); ``` ``` -------------------------------- ### CLI Basic Commands Source: https://context7.com/johnsoncodehk/tsslint/llms.txt Execute linting tasks for projects, files, and CI/CD pipelines using the TSSLint CLI. ```bash # Lint a single project npx tsslint --project tsconfig.json # Lint and auto-fix violations npx tsslint --project tsconfig.json --fix # Lint multiple projects with glob patterns npx tsslint --project packages/*/tsconfig.json # Lint multiple projects with brace expansion npx tsslint --project {tsconfig.json,packages/*/tsconfig.json} # Filter files to lint npx tsslint --project tsconfig.json --filter src/components # Force re-lint without cache npx tsslint --project tsconfig.json --force ``` -------------------------------- ### Linting a Project with TSSLint CLI Source: https://github.com/johnsoncodehk/tsslint/blob/master/README.md Use the `npx tsslint` command to lint a project. Specify the project path using the `--project` flag. ```bash # Lint a project npx tsslint --project path/to/tsconfig.json ``` -------------------------------- ### Import TSLint Rules Source: https://context7.com/johnsoncodehk/tsslint/llms.txt Use importTSLintRules to migrate legacy TSLint configurations to TSSLint. ```typescript import { defineConfig, importTSLintRules } from '@tsslint/config'; export default defineConfig({ rules: await importTSLintRules({ // TSLint core rules 'no-console': true, 'strict-boolean-expressions': true, // Rules with options 'member-ordering': [true, { order: 'fields-first' }], // Severity levels 'no-debugger': 'error', 'no-empty': 'warn', }), }); ``` -------------------------------- ### Linting Multiple Projects with TSSLint CLI Source: https://github.com/johnsoncodehk/tsslint/blob/master/README.md Lint multiple projects by providing multiple `--project` flags or using brace expansion for patterns. ```bash # Lint multiple projects npx tsslint --project path/to/tsconfig.json --vue-project apps/web/tsconfig.json ``` ```bash # Using brace expansion for multiple patterns npx tsslint --project {tsconfig.json,packages/*/tsconfig.json,extensions/*/tsconfig.json} ``` -------------------------------- ### Utility Functions Source: https://context7.com/johnsoncodehk/tsslint/llms.txt Helper functions for conditional rule configuration. ```APIDOC ## isCLI ### Description Detects if the code is running in CLI mode to conditionally enable rules or features. ### Usage ```typescript import { isCLI } from '@tsslint/config'; // Example: Only enable expensive rules in CI 'complex-type-check': isCLI() ? ... : () => {} ``` ``` -------------------------------- ### Render a React Component Source: https://github.com/johnsoncodehk/tsslint/blob/master/fixtures/meta-frameworks/fixture.mdx Shows how to render the previously defined 'Component' within JSX. This is a standard way to use components in React applications. ```jsx Hello ``` -------------------------------- ### Import TSL Rules Source: https://context7.com/johnsoncodehk/tsslint/llms.txt Use fromTSLRules to integrate existing TSL (TypeScript Linter) rules. ```typescript import { defineConfig, fromTSLRules } from '@tsslint/config'; import { core } from 'tsl'; export default defineConfig({ // Import all core TSL rules rules: fromTSLRules(core.all()), }); ``` -------------------------------- ### Import ESLint Rules Source: https://context7.com/johnsoncodehk/tsslint/llms.txt Use importESLintRules to convert ESLint core, plugin, and custom rules into TSSLint format within the configuration file. ```typescript import { defineConfig, importESLintRules } from '@tsslint/config'; export default defineConfig({ rules: await importESLintRules({ // ESLint core rules 'no-unused-vars': 'error', 'no-console': 'warn', 'no-debugger': true, // true = 'error' // Rules with options 'max-lines': ['warn', { max: 300, skipBlankLines: true }], // @typescript-eslint plugin rules '@typescript-eslint/no-explicit-any': 'error', '@typescript-eslint/strict-boolean-expressions': ['error', { allowNullableBoolean: true, }], // Other ESLint plugins (must be installed) 'expect-type/expect': true, // Disable a rule 'no-empty': false, // or 'off' or 0 }), }); ``` -------------------------------- ### Configure TypeScript Server Node Path Source: https://github.com/johnsoncodehk/tsslint/blob/master/packages/vscode/README.md Set the absolute path to a compatible Node.js executable in your VS Code settings to ensure the plugin loads correctly. ```json { "typescript.tsserver.nodePath": "/path/to/node-23.6.0" } ``` -------------------------------- ### Define TSSLint Configuration Source: https://context7.com/johnsoncodehk/tsslint/llms.txt Configures linting rules, file inclusion/exclusion patterns, and plugins. Use an array of objects to apply different rules to specific file patterns. ```typescript import { defineConfig, createIgnorePlugin } from '@tsslint/config'; export default defineConfig({ // Include only specific files (glob patterns) include: ['src/**/*.ts'], // Exclude files from linting exclude: ['**/*.spec.ts', '**/*.test.ts'], // Define lint rules rules: { 'no-debugger': (await import('./rules/no-debugger.ts')), 'no-console': (await import('./rules/no-console.ts')), }, // Add plugins for extended functionality plugins: [ createIgnorePlugin('tsslint-ignore', true) ], }); ``` ```typescript import { defineConfig } from '@tsslint/config'; export default defineConfig([ { include: ['**/*.ts'], rules: { 'no-console-ts': (await import('./rules/noConsoleRule.ts')), }, }, { include: ['**/*.vue'], rules: { 'no-console-vue': (await import('./rules/noConsoleRule.ts')), }, }, ]); ``` -------------------------------- ### Configure TSL rules in tsslint.config.ts Source: https://github.com/johnsoncodehk/tsslint/blob/master/README.md Load TSL rules using the fromTSLRules helper within the tsslint configuration file. ```ts import { defineConfig, fromTSLRules } from '@tsslint/config'; import { core } from 'tsl'; export default defineConfig({ rules: fromTSLRules(core.all()), }); ``` -------------------------------- ### defineConfig Source: https://context7.com/johnsoncodehk/tsslint/llms.txt Defines the TSSLint configuration including file filtering, rule definitions, and plugin integration. ```APIDOC ## defineConfig ### Description Defines the TSSLint configuration with rules, plugins, and file filtering options. Accepts a single config object or an array of configs for different file patterns. ### Parameters - **include** (string[]) - Optional - Glob patterns of files to include. - **exclude** (string[]) - Optional - Glob patterns of files to exclude. - **rules** (object) - Optional - Map of rule names to rule definitions. - **plugins** (array) - Optional - List of plugins for extended functionality. ### Request Example ```typescript import { defineConfig, createIgnorePlugin } from '@tsslint/config'; export default defineConfig({ include: ['src/**/*.ts'], exclude: ['**/*.spec.ts', '**/*.test.ts'], rules: { 'no-debugger': (await import('./rules/no-debugger.ts')), }, plugins: [ createIgnorePlugin('tsslint-ignore', true) ], }); ``` ``` -------------------------------- ### Create plugins with definePlugin Source: https://context7.com/johnsoncodehk/tsslint/llms.txt Define plugins to dynamically resolve rules, filter diagnostics, or modify code fixes during the linting process. ```typescript import { definePlugin } from '@tsslint/config'; // Plugin to resolve rules dynamically based on file name const addRulesPlugin = definePlugin(() => ({ resolveRules(fileName, rules) { if (fileName.endsWith('.test.ts')) { // Disable certain rules for test files delete rules['no-console']; } return rules; }, })); // Plugin to filter or modify diagnostics const filterDiagnosticsPlugin = definePlugin(() => ({ resolveDiagnostics(file, diagnostics) { // Filter out specific diagnostics return diagnostics.filter(d => d.code !== 'some-rule-id'); }, })); // Plugin to modify code fixes const modifyFixesPlugin = definePlugin(() => ({ resolveCodeFixes(file, diagnostic, codeFixes) { // Add custom fix options return codeFixes; }, })); export default defineConfig({ plugins: [addRulesPlugin, filterDiagnosticsPlugin, modifyFixesPlugin], }); ``` -------------------------------- ### defineRule Source: https://context7.com/johnsoncodehk/tsslint/llms.txt Creates a custom lint rule with access to TypeScript APIs, the source file, and a reporter function for AST traversal and type-aware analysis. ```APIDOC ## defineRule ### Description Creates a custom lint rule. Provides access to the TypeScript compiler, the current file, the program (for type checking), and a report function to flag issues and provide auto-fixes. ### Parameters - **typescript** (object) - The TypeScript compiler API. - **file** (object) - The current source file being linted. - **program** (object) - The TypeScript program instance. - **report** (function) - Function to report linting issues. ### Request Example ```typescript import { defineRule } from '@tsslint/config'; export default defineRule(({ typescript: ts, file, program, report }) => { const checker = program.getTypeChecker(); ts.forEachChild(file, function cb(node) { // Rule logic here ts.forEachChild(node, cb); }); }); ``` ``` -------------------------------- ### Configuring Ignore Plugin in TSSLint Source: https://github.com/johnsoncodehk/tsslint/blob/master/README.md Configure TSSLint to ignore specific rules by using the `createIgnorePlugin` function in your configuration file. ```typescript import { defineConfig, createIgnorePlugin } from '@tsslint/config'; export default defineConfig({ rules: { ... }, plugins: [ createIgnorePlugin('tsslint-ignore', true) ], }); ``` -------------------------------- ### Configure TSSLint in tsconfig.json Source: https://github.com/johnsoncodehk/tsslint/blob/master/README.md Integrate TSSLint as a plugin within your project's tsconfig.json file for editor integration. ```json { "compilerOptions": { "plugins": [{ "name": "@tsslint/typescript-plugin" }] } } ``` -------------------------------- ### Importing TSLint Rules in TSSLint Configuration Source: https://github.com/johnsoncodehk/tsslint/blob/master/README.md Use the `importTSLintRules` function in `tsslint.config.ts` to load rules from TSLint. It supports third-party TSLint plugins by reading `rulesDirectory` from `tslint.json`. ```typescript import { defineConfig, importTSLintRules } from '@tsslint/config'; export default defineConfig({ rules: { ...await importTSLintRules({ 'no-console': true, 'member-ordering': [true, { order: 'fields-first' }], }), }, }); ``` -------------------------------- ### Importing ESLint Rules in TSSLint Configuration Source: https://github.com/johnsoncodehk/tsslint/blob/master/README.md Use the `importESLintRules` function in `tsslint.config.ts` to load rules from ESLint plugins. It automatically resolves and loads rules based on their prefixes. ```typescript import { defineConfig, importESLintRules } from '@tsslint/config'; export default defineConfig({ rules: { ...await importESLintRules({ 'no-unused-vars': true, '@typescript-eslint/no-explicit-any': true, }), }, }); ``` -------------------------------- ### Configure diagnostics with Reporter API Source: https://context7.com/johnsoncodehk/tsslint/llms.txt Use the report function to define diagnostic severity, visual markers, auto-fixes, and refactoring actions within a rule. ```typescript import { defineRule } from '@tsslint/config'; export default defineRule(({ typescript: ts, file, report }) => { ts.forEachChild(file, function cb(node) { if (node.kind === ts.SyntaxKind.DebuggerStatement) { report('Debugger statement is not allowed.', node.getStart(file), node.getEnd()) // Set severity level .asError() // Mark as error (default is message) // .asWarning() // Mark as warning // .asSuggestion() // Mark as suggestion // Visual markers .withUnnecessary() // Strike-through styling // .withDeprecated() // Deprecated styling // Auto-fix action .withFix( 'Remove debugger statement', () => [{ fileName: file.fileName, textChanges: [{ newText: '', span: { start: node.getStart(file), length: node.getWidth(file) }, }], }], ) // Refactor action (shown in refactor menu) .withRefactor( 'Replace with console.log', () => [{ fileName: file.fileName, textChanges: [{ newText: 'console.log("breakpoint");', span: { start: node.getStart(file), length: node.getWidth(file) }, }], }], ) // Disable caching for this diagnostic .withoutCache() // Adjust stack trace for debugging (advanced) .at(new Error(), 2); } ts.forEachChild(node, cb); }); }); ``` -------------------------------- ### Suppress diagnostics with createIgnorePlugin Source: https://context7.com/johnsoncodehk/tsslint/llms.txt Enable ignore comments in source code to suppress specific diagnostics using the ignore plugin. ```typescript import { defineConfig, createIgnorePlugin } from '@tsslint/config'; export default defineConfig({ rules: { /* ... */ }, plugins: [ // Single-line ignore: // tsslint-ignore createIgnorePlugin('tsslint-ignore', true), // With reporting of unused ignore comments // createIgnorePlugin('tsslint-ignore', true), ], }); // Usage in code: // // tsslint-ignore // console.log('This line is ignored'); // // tsslint-ignore no-console // console.log('Only no-console rule is ignored'); ``` -------------------------------- ### Conditional CLI Rules Source: https://context7.com/johnsoncodehk/tsslint/llms.txt Use the isCLI utility to conditionally enable rules based on the execution environment. ```typescript import { defineConfig, isCLI } from '@tsslint/config'; export default defineConfig({ rules: { // Only enable expensive rules in CI 'complex-type-check': isCLI() ? (await import('./rules/complex-type-check.ts')) : () => {}, }, }); ``` -------------------------------- ### Auto-fixing Violations with TSSLint CLI Source: https://github.com/johnsoncodehk/tsslint/blob/master/README.md Run TSSLint with the `--fix` flag to automatically fix reported violations. ```bash # Auto-fix violations npx tsslint --project path/to/tsconfig.json --fix ``` -------------------------------- ### Adjusting Stack Depth for `report()` Source: https://github.com/johnsoncodehk/tsslint/blob/master/README.md Use the `.at()` method to adjust the stack depth when wrapping `report()` in a helper function, ensuring the stack trace points to the correct logic. ```typescript report('message', start, end) .at(new Error(), 2) // Adjusts the stack index to skip the helper function's frame .withFix(...); ``` -------------------------------- ### Define Custom Lint Rules Source: https://context7.com/johnsoncodehk/tsslint/llms.txt Creates custom rules by traversing the AST. Rules can report issues and provide auto-fixes or utilize the TypeScript type checker for type-aware analysis. ```typescript import { defineRule } from '@tsslint/config'; export default defineRule(({ typescript: ts, file, report }) => { ts.forEachChild(file, function cb(node) { // Detect console.* calls if ( ts.isPropertyAccessExpression(node) && ts.isIdentifier(node.expression) && node.expression.text === 'console' ) { report( `Calls to 'console.x' are not allowed.`, node.parent.getStart(file), node.parent.getEnd(), ).withFix( `Remove 'console.${node.name.text}'`, () => [{ fileName: file.fileName, textChanges: [{ newText: '/* deleted */', span: { start: node.parent.getStart(file), length: node.parent.getWidth(file), }, }], }], ); } ts.forEachChild(node, cb); }); }); ``` ```typescript import { defineRule } from '@tsslint/config'; export default defineRule(({ typescript: ts, file, program, report }) => { const checker = program.getTypeChecker(); ts.forEachChild(file, function cb(node) { if (ts.isVariableDeclaration(node) && node.initializer) { const type = checker.getTypeAtLocation(node.initializer); const typeName = checker.typeToString(type); if (typeName === 'any') { report( 'Avoid using implicit any type.', node.getStart(file), node.getEnd(), ).asWarning(); } } ts.forEachChild(node, cb); }); }); ``` -------------------------------- ### Include TypeScript diagnostics with createDiagnosticsPlugin Source: https://context7.com/johnsoncodehk/tsslint/llms.txt Integrate built-in TypeScript semantic, syntactic, or declaration diagnostics into the TSSLint report. ```typescript import { defineConfig, createDiagnosticsPlugin } from '@tsslint/config'; export default defineConfig({ rules: { /* ... */ }, plugins: [ // Include semantic diagnostics (type errors) createDiagnosticsPlugin('semantic'), // Include syntactic diagnostics // createDiagnosticsPlugin('syntactic'), // Include declaration diagnostics // createDiagnosticsPlugin('declaration'), // Include multiple types // createDiagnosticsPlugin(['semantic', 'syntactic']), ], }); ``` -------------------------------- ### Override diagnostic severity with createCategoryPlugin Source: https://context7.com/johnsoncodehk/tsslint/llms.txt Use glob patterns to override the severity level of specific rules. ```typescript import { defineConfig, createCategoryPlugin } from '@tsslint/config'; import ts from 'typescript'; export default defineConfig({ rules: { /* ... */ }, plugins: [ createCategoryPlugin({ // Make all no-* rules warnings 'no-*': ts.DiagnosticCategory.Warning, // Make specific rule an error 'strict-null-checks': ts.DiagnosticCategory.Error, }), ], }); ``` === COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.