Skip to content

Commit

Permalink
Add support for stylelint 16 (#187)
Browse files Browse the repository at this point in the history
Co-authored-by: Krister Kari <[email protected]>
  • Loading branch information
kristerkari and kristerkari authored Jan 21, 2024
1 parent 77650db commit 26cdc5c
Show file tree
Hide file tree
Showing 8 changed files with 546 additions and 452 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ jobs:
strategy:
fail-fast: false
matrix:
node: [18, 20]
node: [20]
os: [ubuntu-latest, windows-latest]

steps:
Expand Down
18 changes: 10 additions & 8 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,8 @@
"prepublish": "npm run build",
"pretest": "npm run lint",
"release": "np",
"jest": "jest",
"test": "jest --coverage"
"jest": "cross-env NODE_OPTIONS=\"--experimental-vm-modules --no-warnings\" jest",
"test": "cross-env NODE_OPTIONS=\"--experimental-vm-modules --no-warnings\" jest --coverage"
},
"repository": {
"type": "git",
Expand All @@ -46,7 +46,7 @@
"url": "https://github.com/kristerkari/stylelint-react-native/issues"
},
"engines": {
"node": ">=6"
"node": ">=18.12.0"
},
"homepage": "https://github.com/kristerkari/stylelint-react-native#readme",
"jest": {
Expand All @@ -68,6 +68,7 @@
"statements": 75
}
},
"preset": "jest-preset-stylelint",
"setupFiles": [
"./jest-setup.js"
],
Expand All @@ -78,7 +79,7 @@
"testRegex": ".*\\.test\\.js$|src/.*/__tests__/.*\\.js$"
},
"peerDependencies": {
"stylelint": "^8.0.0 || ^9.0.0 || ^10.0.0 || ^11.0.0 || ^12.0.0 || ^13.0.0 || ^14.0.0 || ^15.0.0"
"stylelint": "^8.0.0 || ^9.0.0 || ^10.0.0 || ^11.0.0 || ^12.0.0 || ^13.0.0 || ^14.0.0 || ^15.0.0 || ^16.0.0"
},
"lint-staged": {
"**/*.{js,json,md}": [
Expand Down Expand Up @@ -128,21 +129,22 @@
"@stylelint/postcss-css-in-js": "^0.38.0",
"babel-plugin-istanbul": "^6.0.0",
"babel-preset-jest": "^29.2.0",
"cross-env": "^7.0.3",
"eslint": "^8.31.0",
"eslint-config-stylelint": "^20.0.0",
"eslint-plugin-sort-requires": "^2.1.0",
"husky": "^7.0.1",
"jest": "^29.4.2",
"jest-cli": "^29.4.2",
"jest-preset-stylelint": "^6.0.0",
"jest": "^29.7.0",
"jest-cli": "^29.7.0",
"jest-preset-stylelint": "^7.0.0",
"lint-staged": "^13.1.0",
"np": "^8.0.4",
"postcss-less": "^5.0.0",
"postcss-scss": "^4.0.2",
"postcss-syntax": "^0.36.2",
"prettier": "^3.0.0",
"rimraf": "^5.0.1",
"stylelint": "^15.1.0"
"stylelint": "^16.2.0"
},
"prettier": {
"semi": true,
Expand Down
2 changes: 1 addition & 1 deletion src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,4 @@ const rulesPlugins = Object.keys(rules).map(ruleName => {
return createPlugin(namespace(ruleName), rules[ruleName]);
});

export default rulesPlugins;
module.exports = rulesPlugins;
2 changes: 1 addition & 1 deletion src/rules/font-weight-no-ignored-values/index.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { utils } from "stylelint";
import { namespace } from "../../utils";

const declarationValueIndex = require("stylelint/lib/utils/declarationValueIndex");
const declarationValueIndex = require("../../utils/declarationValueIndex");

export const ruleName = namespace("font-weight-no-ignored-values");

Expand Down
4 changes: 3 additions & 1 deletion src/rules/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,10 @@ import cssPropertyNoUnknown from "./css-property-no-unknown";
import stylePropertyNoUnknown from "./style-property-no-unknown";
import fontWeightNoIgnoredValues from "./font-weight-no-ignored-values";

export default {
const rules = {
"font-weight-no-ignored-values": fontWeightNoIgnoredValues,
"css-property-no-unknown": cssPropertyNoUnknown,
"style-property-no-unknown": stylePropertyNoUnknown
};

module.exports = rules;
28 changes: 28 additions & 0 deletions src/utils/declarationValueIndex.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
const validateTypes = require("./validateTypes");

/**
* Get the index of a declaration's value
*
* @param {import('postcss').Declaration} decl
* @returns {number}
*/
function declarationValueIndex(decl) {
const raws = decl.raws;
const prop = raws.prop;

return [
validateTypes.isObject(prop) && "prefix" in prop && prop.prefix,
(validateTypes.isObject(prop) && "raw" in prop && prop.raw) || decl.prop,
validateTypes.isObject(prop) && "suffix" in prop && prop.suffix,
raws.between || ":",
raws.value && "prefix" in raws.value && raws.value.prefix
].reduce((/** @type {number} */ count, str) => {
if (validateTypes.isString(str)) {
return count + str.length;
}

return count;
}, 0);
}

module.exports = declarationValueIndex;
19 changes: 19 additions & 0 deletions src/utils/validateTypes.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
/** * Checks if the value is an object.
* @param {unknown} value
* @returns {value is object}
*/
function isObject(value) {
return value !== null && typeof value === "object";
}

/**
* Checks if the value is a string or a String object.
* @param {unknown} value
* @returns {value is string}
*/
function isString(value) {
return typeof value === "string" || value instanceof String;
}

exports.isObject = isObject;
exports.isString = isString;
Loading

0 comments on commit 26cdc5c

Please sign in to comment.