Skip to content

Commit

Permalink
Add @types/postcss-less (#4920)
Browse files Browse the repository at this point in the history
This is a part of #4496 and improves type-checking about LESS. (fixing `// @ts-ignore`)

https://github.com/DefinitelyTyped/DefinitelyTyped/tree/master/types/postcss-less
  • Loading branch information
ybiquitous committed Sep 13, 2020
1 parent 6e1ab1c commit 528c06d
Show file tree
Hide file tree
Showing 7 changed files with 22 additions and 15 deletions.
8 changes: 5 additions & 3 deletions lib/utils/isLessVariable.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,12 @@
const hasBlock = require('./hasBlock');

/**
* @param {import('postcss').AtRule} atRule
* @param {import('postcss').AtRule | import('postcss-less').AtRule} atRule
* @returns {boolean}
*/
module.exports = function (atRule) {
// @ts-ignore TODO TYPES LESS property variable does not exists in types
return (atRule.type === 'atrule' && atRule.variable && !hasBlock(atRule)) || false;
return (
(atRule.type === 'atrule' && 'variable' in atRule && atRule.variable && !hasBlock(atRule)) ||
false
);
};
8 changes: 3 additions & 5 deletions lib/utils/isStandardSyntaxAtRule.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
/**
* Check whether a at-rule is standard
*
* @param {import('postcss').AtRule} atRule postcss at-rule node
* @param {import('postcss').AtRule | import('postcss-less').AtRule} atRule postcss at-rule node
* @return {boolean} If `true`, the declaration is standard
*/
module.exports = function (atRule) {
Expand All @@ -13,15 +13,13 @@ module.exports = function (atRule) {
}

// Ignore Less mixins
// @ts-ignore TODO TYPES Is this property really exists?
if (atRule.mixin) {
if ('mixin' in atRule && atRule.mixin) {
return false;
}

// Ignore Less detached ruleset `@detached-ruleset: { background: red; }; .top { @detached-ruleset(); }`
if (
// @ts-ignore TODO TYPES Is this property really exists?
atRule.variable ||
('variable' in atRule && atRule.variable) ||
(!atRule.nodes && atRule.raws.afterName === '' && atRule.params[0] === '(')
) {
return false;
Expand Down
5 changes: 2 additions & 3 deletions lib/utils/isStandardSyntaxDeclaration.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ function isStandardSyntaxLang(lang) {
/**
* Check whether a declaration is standard
*
* @param {import('postcss').Declaration} decl
* @param {import('postcss').Declaration | import('postcss-less').Declaration} decl
*/
module.exports = function (decl) {
const prop = decl.prop;
Expand Down Expand Up @@ -53,8 +53,7 @@ module.exports = function (decl) {
}

// Less &:extend
// @ts-ignore TODO TYPES extend does not exists
if (decl.extend) {
if ('extend' in decl && decl.extend) {
return false;
}

Expand Down
5 changes: 2 additions & 3 deletions lib/utils/isStandardSyntaxRule.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ const isStandardSyntaxSelector = require('../utils/isStandardSyntaxSelector');
/**
* Check whether a Node is a standard rule
*
* @param {import('postcss').Rule} rule
* @param {import('postcss').Rule | import('postcss-less').Rule} rule
* @returns {boolean}
*/
module.exports = function (rule) {
Expand Down Expand Up @@ -39,8 +39,7 @@ module.exports = function (rule) {
}

// Ignore Less &:extend rule
// @ts-ignore TODO TYPES support LESS and SASS types somehow
if (rule.extend) {
if ('extend' in rule && rule.extend) {
return false;
}

Expand Down
9 changes: 9 additions & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -171,6 +171,7 @@
"@types/imurmurhash": "^0.1.1",
"@types/lodash": "^4.14.161",
"@types/micromatch": "^4.0.1",
"@types/postcss-less": "^3.1.1",
"@types/postcss-safe-parser": "^4.0.0",
"@types/style-search": "^0.1.1",
"@types/svg-tags": "^1.0.0",
Expand Down
1 change: 0 additions & 1 deletion types/global.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,5 @@ declare module '@stylelint/postcss-css-in-js';
declare module '@stylelint/postcss-markdown';
declare module 'import-lazy';
declare module 'postcss-html';
declare module 'postcss-less';
declare module 'postcss-sass';
declare module 'sugarss';

0 comments on commit 528c06d

Please sign in to comment.