Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions eslint.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@ export default defineConfig([
// TypeScript
...tseslint.config({
files: ["**/*.ts"],
ignores: ["**/tests/**/*.ts"],
extends: [...tseslint.configs.strict, ...tseslint.configs.stylistic],
rules: {
"no-use-before-define": "off",
Expand Down
26 changes: 20 additions & 6 deletions packages/core/src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -666,22 +666,36 @@ export interface LinterOptionsConfig {
* Indicates what to do when an unused disable directive is found.
*/
reportUnusedDisableDirectives?: boolean | Severity;

/**
* A severity value indicating if and how unused inline configs should be
* tracked and reported.
*/
reportUnusedInlineConfigs?: Severity;
}

/**
* Shared settings that are accessible from within plugins.
* The configuration for a rule.
*/
export type SettingsConfig = Record<string, unknown>;
export type RuleConfig<RuleOptions extends unknown[] = unknown[]> =
| Severity
| [Severity, ...RuleOptions];

/* eslint-disable @typescript-eslint/consistent-indexed-object-style -- needed to allow extension */
/**
* The configuration for a rule.
* A collection of rules and their configurations.
*/
export type RuleConfig = Severity | [Severity, ...unknown[]];
export interface RulesConfig {
[key: string]: RuleConfig;
}

/**
* A collection of rules and their configurations.
* A collection of settings.
*/
export type RulesConfig = Record<string, RuleConfig>;
export interface SettingsConfig {
[key: string]: unknown;
}
/* eslint-enable @typescript-eslint/consistent-indexed-object-style -- needed to allow extension */

//------------------------------------------------------------------------------
// Languages
Expand Down
38 changes: 38 additions & 0 deletions packages/core/tests/types/types.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,15 +15,18 @@ import type {
Language,
LanguageContext,
LanguageOptions,
LinterOptionsConfig,
OkParseResult,
ParseResult,
RuleConfig,
RuleContext,
RuleDefinition,
RulesConfig,
RulesMeta,
RuleTextEdit,
RuleTextEditor,
RuleVisitor,
SettingsConfig,
SourceLocation,
SourceRange,
TextSourceCode,
Expand All @@ -46,6 +49,41 @@ interface TestRootNode {
length: number;
}

//-----------------------------------------------------------------------------
// Tests for config types
//-----------------------------------------------------------------------------

const emptyRules: RulesConfig = {};

const rules: RulesConfig = {
"no-console": "error",
"no-unused-vars": 0,
"json/no-duplicate-keys": ["warn"],
"css/use-baseline": [1, { available: "widely" }],
};

const emptySettings: SettingsConfig = {};

const settings: SettingsConfig = {
foo: true,
bar: "baz",
};

const ruleConfig1: RuleConfig = "error";
const ruleConfig2: RuleConfig = 1;
const ruleConfig3: RuleConfig = ["error", { foo: "bar" }];
const ruleConfig4: RuleConfig<string[]> = ["error", "foo", "bar"];
const ruleConfig5: RuleConfig<[{ available: "widely" | "newly" }]> = [
"error",
{ available: "widely" },
];

const linterConfig: LinterOptionsConfig = {
noInlineConfig: true,
reportUnusedDisableDirectives: "error",
reportUnusedInlineConfigs: "warn",
};

//-----------------------------------------------------------------------------
// Tests for shared types
//-----------------------------------------------------------------------------
Expand Down