Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Removing already gone function from stylelint declaration #56514

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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
118 changes: 35 additions & 83 deletions types/stylelint/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,30 +10,18 @@
import { GlobbyOptions } from 'globby';
import * as postcss from 'postcss';

export type FormatterType =
| "json"
| "string"
| "verbose"
| "compact"
| "unix"
| ((results: LintResult[]) => string);

export type SyntaxType = "css-in-js"
| "html"
| "less"
| "markdown"
| "sass"
| "scss"
| "sugarss";

export type Severity = "warning" | "error";
export type FormatterType = 'json' | 'string' | 'verbose' | 'compact' | 'unix' | ((results: LintResult[]) => string);

export type SyntaxType = 'css-in-js' | 'html' | 'less' | 'markdown' | 'sass' | 'scss' | 'sugarss';

export type Severity = 'warning' | 'error';

export interface Configuration {
rules: Record<string, any>;
extends: string | string[];
plugins: string[];
processors: string[];
ignoreFiles: string|string[];
ignoreFiles: string | string[];
defaultSeverity: Severity;
}

Expand Down Expand Up @@ -95,15 +83,17 @@ export namespace formatters {

export function lint(options?: Partial<LinterOptions>): Promise<LinterResult>;

export type ValidateOptionsAssertion = {
actual: any;
possible?: any;
optional?: false | undefined;
} | {
actual?: any;
possible: any;
optional: true;
};
export type ValidateOptionsAssertion =
| {
actual: any;
possible?: any;
optional?: false;
}
| {
actual?: any;
possible: any;
optional: true;
};

export type RuleMessageValue = string | ((...args: any[]) => string);

Expand All @@ -113,66 +103,28 @@ export namespace utils {
result: postcss.Result;
message: string;
node: postcss.Node;
index?: number | undefined;
word?: string | undefined;
line?: number | undefined;
index?: number;
word?: string;
line?: number;
}): void;

function ruleMessages<T extends {[key: string]: RuleMessageValue}>(
ruleName: string,
messages: T): T;

function validateOptions(result: postcss.Result, ruleName: string,
...options: ValidateOptionsAssertion[]): boolean;

function checkAgainstRule(options: {
ruleName: string;
ruleSettings: any;
root: any;
}, callback: (warning: string) => void): void;
}
function ruleMessages<T extends { [key: string]: RuleMessageValue }>(ruleName: string, messages: T): T;

export type Plugin = (primaryOption: any, secondaryOptions?: object) =>
(root: postcss.Root, result: postcss.Result) => void|PromiseLike<void>;
function validateOptions(result: postcss.Result, ruleName: string, ...options: ValidateOptionsAssertion[]): boolean;

export function createPlugin(
ruleName: string,
plugin: Plugin
): any;

export interface RuleTesterResult {
expected: number;
actual: number;
description: string;
function checkAgainstRule(
options: {
ruleName: string;
ruleSettings: any;
root: any;
},
callback: (warning: string) => void,
): void;
}

export interface RuleTesterTest {
code: string;
description?: string | undefined;
}

export interface RuleTesterTestRejected extends RuleTesterTest {
line?: number | undefined;
column?: number | undefined;
only?: boolean | undefined;
message?: string | undefined;
}

export interface RuleTesterSchema {
ruleName: string;
syntax?: SyntaxType | undefined;
config?: any;
accept?: RuleTesterTest[] | undefined;
reject?: RuleTesterTestRejected[] | undefined;
}

export interface RuleTesterContext {
comparisonCount: number;
completeAssertionDescription: string;
caseDescription: string;
only?: boolean | undefined;
}
export type Plugin = (
primaryOption: any,
secondaryOptions?: object,
) => (root: postcss.Root, result: postcss.Result) => void | PromiseLike<void>;

export function createRuleTester(
fn: (result: Promise<RuleTesterResult[]>, context: RuleTesterContext) => void
): (rule: Plugin, schema: RuleTesterSchema) => void;
export function createPlugin(ruleName: string, plugin: Plugin): any;
87 changes: 34 additions & 53 deletions types/stylelint/stylelint-tests.ts
Original file line number Diff line number Diff line change
@@ -1,35 +1,32 @@
import {
LinterOptions,
createPlugin,
FormatterType,
SyntaxType,
lint,
LintResult,
LinterOptions,
LinterResult,
createPlugin,
utils,
createRuleTester,
RuleTesterContext,
RuleTesterResult,
LintResult,
Plugin,
SyntaxType,
utils,
Warning,
} from 'stylelint';

const options: Partial<LinterOptions> = {
allowEmptyInput: true,
code: "div { color: red }",
files: ["**/**.scss"],
formatter: "json",
code: 'div { color: red }',
files: ['**/**.scss'],
formatter: 'json',
globbyOptions: {
cwd: "./"
cwd: './',
},
cache: true,
cacheLocation: "./stylelint.cache.json",
cacheLocation: './stylelint.cache.json',
ignoreDisables: true,
reportDescriptionlessDisables: true,
reportInvalidScopeDisables: true,
reportNeedlessDisables: true,
ignorePath: 'foo',
syntax: "scss"
syntax: 'scss',
};

lint(options).then((x: LinterResult) => {
Expand All @@ -41,58 +38,42 @@ lint(options).then((x: LinterResult) => {
}
});

const formatter: FormatterType = "json";
const formatter: FormatterType = 'json';

const syntax: SyntaxType = "scss";
const syntax: SyntaxType = 'scss';

const ruleName = "sample-rule";
const ruleName = 'sample-rule';
const messages = utils.ruleMessages(ruleName, {
violation: "This a rule violation message",
violation: 'This a rule violation message',
warning: (reason: string) => `This is not allowed because ${reason}`,
});

const testPlugin: Plugin = (options) => {
const testPlugin: Plugin = options => {
return (root, result) => {
const validOptions = utils.validateOptions(result, ruleName, { actual: options });
if (!validOptions) {
return;
}

utils.checkAgainstRule({
ruleName: "at-rule-empty-line-before",
ruleSettings: ["always"],
root,
}, warning => {
utils.report({
ruleName,
result,
message: messages.warning(warning),
node: root,
index: 1,
word: "foo",
line: 2,
});
});
utils.checkAgainstRule(
{
ruleName: 'at-rule-empty-line-before',
ruleSettings: ['always'],
root,
},
warning => {
utils.report({
ruleName,
result,
message: messages.warning(warning),
node: root,
index: 1,
word: 'foo',
line: 2,
});
},
);
};
};

createPlugin(ruleName, testPlugin);

const tester = createRuleTester(
(result: Promise<RuleTesterResult[]>, context: RuleTesterContext) => {
return;
}
);

tester(testPlugin, {
ruleName: 'foo',
config: [true, 1],
accept: [
{ code: 'test' },
{ code: 'test2', description: 'testing' }
],
reject: [
{ code: 'testreject', line: 1, column: 1 },
{ code: 'test2reject', message: 'x', line: 1, column: 1 }
]
});
4 changes: 2 additions & 2 deletions types/stylelint/v7/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,9 @@
// Definitions by: Alan Agius <https://github.com/alan-agius4>
// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped

export type FormatterType = "json" | "string" | "verbose";
export type FormatterType = 'json' | 'string' | 'verbose';

export type SyntaxType = "scss" | "sass" | "less" | "sugarss";
export type SyntaxType = 'scss' | 'sass' | 'less' | 'sugarss';

export interface LinterOptions {
code?: string | undefined;
Expand Down
16 changes: 8 additions & 8 deletions types/stylelint/v7/stylelint-tests.ts
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
import { LinterOptions, FormatterType, SyntaxType, lint, LintResult, LinterResult } from "stylelint";
import { LinterOptions, FormatterType, SyntaxType, lint, LintResult, LinterResult } from 'stylelint';

const options: LinterOptions = {
code: "div { color: red }",
files: ["**/**.scss"],
formatter: "json",
code: 'div { color: red }',
files: ['**/**.scss'],
formatter: 'json',
cache: true,
cacheLocation: "./stylelint.cache.json",
cacheLocation: './stylelint.cache.json',
ignoreDisables: true,
reportNeedlessDisables: true,
ignorePath: true,
syntax: "scss"
syntax: 'scss',
};

lint(options).then((x: LinterResult) => {
Expand All @@ -19,6 +19,6 @@ lint(options).then((x: LinterResult) => {
const results: LintResult[] = x.results;
});

const formatter: FormatterType = "json";
const formatter: FormatterType = 'json';

const syntax: SyntaxType = "scss";
const syntax: SyntaxType = 'scss';