Skip to content

Commit

Permalink
🤖 Merge PR #56514 Removing already gone function from stylelint decla…
Browse files Browse the repository at this point in the history
…ration by @lucavb

* chore(stylelint) running prettier fix

* chore(stylelint) removing redundant undefined declarations

Property is optional, so no need to specify `undefined` as a possible value. See: https://github.com/Microsoft/dtslint/blob/master/docs/no-redundant-undefined.md

* fix(stylelint) removing createRuleTester from exports

This export has been removed in version 12 of stylelint.
stylelint/stylelint#4385
https://github.com/stylelint/stylelint/releases/tag/12.0.0
  • Loading branch information
lucavb committed Oct 15, 2021
1 parent fe12440 commit 0e11115
Show file tree
Hide file tree
Showing 4 changed files with 79 additions and 146 deletions.
118 changes: 35 additions & 83 deletions types/stylelint/index.d.ts
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
@@ -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
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
@@ -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';

0 comments on commit 0e11115

Please sign in to comment.