Skip to content

Commit

Permalink
feat: support stylelint v14
Browse files Browse the repository at this point in the history
  • Loading branch information
AndyOGo committed Nov 6, 2021
1 parent 4c86a7a commit 3790437
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 39 deletions.
5 changes: 2 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@
},
"homepage": "https://github.com/AndyOGo/stylelint-declaration-strict-value#readme",
"peerDependencies": {
"stylelint": ">=7 <=13"
"stylelint": ">=7 <=14"
},
"devDependencies": {
"@babel/cli": "^7.12.8",
Expand All @@ -63,7 +63,6 @@
"@semantic-release/changelog": "^5.0.1",
"@semantic-release/exec": "^5.0.0",
"@semantic-release/git": "^9.0.0",
"@types/stylelint": "^9.10.1",
"@typescript-eslint/eslint-plugin": "^4.8.2",
"@typescript-eslint/parser": "^4.8.2",
"babel-register-ts": "^7.0.0",
Expand All @@ -83,7 +82,7 @@
"pinst": "^2.1.6",
"prettier": "^2.2.1",
"semantic-release": "^17.3.0",
"stylelint": "^13.8.0",
"stylelint": "^14.0.1",
"stylelint-test-rule-tape": "^0.2.0",
"typedoc": "^0.20.10",
"typedoc-plugin-markdown": "^3.2.1",
Expand Down
2 changes: 1 addition & 1 deletion src/defaults.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import type { Node, Root } from 'postcss';
import type { Node, Root } from 'stylelint/node_modules/postcss';

/**
* Rule Name.
Expand Down
47 changes: 12 additions & 35 deletions src/index.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import type { Declaration, Root, Result, AtRule } from 'postcss';
import stylelint from 'stylelint';
import type { Declaration, Root, AtRule } from 'stylelint/node_modules/postcss';
import stylelint, { Plugin, PluginContext, PostcssResult } from 'stylelint';
import shortCSS from 'shortcss';
import list from 'shortcss/lib/list';
import cssValues from 'css-values';
Expand Down Expand Up @@ -108,27 +108,6 @@ const mapIgnoreValue = (ignoreValue: IgnoreValue) =>
? stringToRegex(`${ignoreValue}`)
: new RegExp(`^${ignoreValue}$`);

/**
* A rule function essentially returns a little PostCSS plugin.
* It will report violations of this rule.
*
* @param root - PostCSS root (the parsed AST).
* @param result - PostCSS lazy result.
*/
type PostCSSPlugin = (root: Root, result: Result) => void | PromiseLike<void>;

/**
* Third Stylelint plugin context parameter.
*/
interface StylelintContext {
/**
* Wheter or not stylelint was executed with `--fix` option.
*
* @defaultValue false
*/
fix?: boolean;
}

/**
* A string or regular expression matching a CSS property name.
*/
Expand All @@ -150,19 +129,17 @@ type PrimaryOptions = CSSPropertyName | CSSPropertyName[];
*
* @returns Returns a PostCSS Plugin.
*/
interface StylelintRuleFunction {
(
primaryOption: PrimaryOptions,
secondaryOptions?: SecondaryOptions,
context?: StylelintContext
): PostCSSPlugin;
primaryOptionArray: boolean;
}
const ruleFunction: StylelintRuleFunction = (
properties: string | string[],
type StylelintPlugin<P = unknown, S = unknown> = Plugin<P, S> & {
/**
* @see: https://stylelint.io/developer-guide/plugins/#allow-primary-option-arrays
*/
primaryOptionArray?: boolean;
};
const ruleFunction: StylelintPlugin<PrimaryOptions, SecondaryOptions> = (
properties: PrimaryOptions,
options: SecondaryOptions,
context: StylelintContext = {}
) => (root: Root, result: Result) => {
context: PluginContext = {}
) => (root: Root, result: PostcssResult) => {
// fix #142
// @see https://github.com/stylelint/stylelint/pull/672/files#diff-78f1c80ffb2836008dd194b3b0ca28f9b46e4897b606f0b3d25a29e57a8d3e61R74
// @see https://stylelint.io/user-guide/configure#message
Expand Down

0 comments on commit 3790437

Please sign in to comment.