2 lines
5.6 KiB
JavaScript
2 lines
5.6 KiB
JavaScript
import e from"stylelint";import n from"shortcss";import t from"shortcss/lib/list";import r from"css-values";import o from"path";function s(){return(s=Object.assign?Object.assign.bind():function(e){for(var n=1;n<arguments.length;n++){var t=arguments[n];for(var r in t)Object.prototype.hasOwnProperty.call(t,r)&&(e[r]=t[r])}return e}).apply(this,arguments)}const i="scale-unlimited/declaration-strict-value",a=(e,n)=>"object"==typeof e&&Object.hasOwnProperty.call(e,n),l={ignoreVariables:!0,ignoreFunctions:!0,ignoreKeywords:null,ignoreValues:null,expandShorthand:!1,recurseLonghand:!1,severity:"error",message:void 0,disableFix:!1,autoFixFunc:null};function u(e){const n=typeof e;return"string"===n||"number"===n}function c(e){return u(e)||Array.isArray(e)&&e.every(e=>u(e))}function f(e){return!("object"!=typeof e||!e)&&Object.keys(e).every(n=>c(e[n]))}function p(e){return!("object"!=typeof e||!e)&&Object.keys(e).every(n=>"boolean"==typeof e[n])}function g(e){if("object"!=typeof e)return!1;const n=Object.keys(l);return!(!Object.keys(e).every(e=>n.indexOf(e)>-1)||"ignoreVariables"in e&&"boolean"!=typeof e.ignoreVariables&&!p(e.ignoreVariables)&&null!==e.ignoreVariables||"ignoreFunctions"in e&&"boolean"!=typeof e.ignoreFunctions&&!p(e.ignoreFunctions)&&null!==e.ignoreFunctions||"severity"in e&&"string"!=typeof e.severity&&null!==e.severity||"ignoreKeywords"in e&&!c(e.ignoreKeywords)&&!f(e.ignoreKeywords)||"ignoreValues"in e&&!c(e.ignoreValues)&&!f(e.ignoreValues)||"expandShorthand"in e&&"boolean"!=typeof e.expandShorthand&&null!==e.expandShorthand||"recurseLonghand"in e&&"boolean"!=typeof e.recurseLonghand&&null!==e.recurseLonghand||"message"in e&&"string"!=typeof e.message&&null!==e.message||"disableFix"in e&&"boolean"!=typeof e.disableFix&&null!==e.disableFix||"autoFixFunc"in e&&"function"!=typeof e.autoFixFunc&&"string"!=typeof e.autoFixFunc&&null!==e.autoFixFunc)}function y(e){let n;if(Array.isArray(e)){const t=e.pop();n=e.length?`${e.join(", ")} or ${t}`:t}else n=e;return n}function d(e,n){return"boolean"==typeof e?e:"object"==typeof e&&e&&{}.hasOwnProperty.call(e,n)?e[n]:!!e}function h(e,n){if(!e)return null;let t=e;return a(t,n)?t=t[n]:a(t,"")&&(t=t[""]),Array.isArray(t)?t:[t]}function b(e,n){if(!e)return null;let t=e;return a(t,n)?t=t[n]:a(t,"")&&(t=t[""]),Array.isArray(t)?t:[t]}const{utils:x}=e,m=x.ruleMessages(i,{expected:function(e,n,t){return`Expected ${e} for "${n}" of "${t}"`},customExpected:function(e,n,t,r){return r.replace("${types}",e).replace("${value}",n).replace("${property}",t)},failedToFix:function(e,n,t){return e&&("string"==typeof e||e instanceof Error)?"string"==typeof e?e:e.message:`Property "${t}" with value "${n}" can't be autofixed`}}),v=/^(?:@|\$|--).+$/,F=/^-?(?:@.+|(?:(?:[a-zA-Z_-]|[^\x20-\x7F])+(?:[a-zA-Z0-9_-]|[^\x20-\x7F])*\.)?\$.+|var\(\s*--[\s\S]+\))$/,w=/^(?!var\(\s*--)[\s\S]+\([\s\S]*\)$/,$=/^\/(.*)\/([a-zA-Z]*)$/,j=/color/,O=e=>$.test(e),V=e=>{const[n,t]=(e=>e.match($).slice(1))(e);return new RegExp(n,t)},A=e=>O(""+e)?V(""+e):new RegExp(`^${e}$`),E=(e,a,u={})=>(f,p)=>{if(p&&p.stylelint&&p.stylelint.customMessages&&p.stylelint.customMessages[i]&&delete p.stylelint.customMessages[i],!x.validateOptions(p,i,{actual:e,possible:c},{actual:a,possible:g,optional:!0}))return;Array.isArray(e)||(e=[e]);const $=s({},l,a),{ignoreVariables:E,ignoreFunctions:k,ignoreKeywords:S,ignoreValues:K,message:R,disableFix:P,autoFixFunc:L,expandShorthand:M,recurseLonghand:N}=$,q=function(e,n,t){if("function"==typeof e)return e;if("string"==typeof e){let n;try{n=require.resolve(e)}catch(t){n=require.resolve(o.join(process.cwd(),e))}return require(n)}return!n&&t&&console.warn(`No \`autoFix\` function provided, consider using \`disableFix\` for "${i}"`),null}(L,P,u.fix),z=S?{}:null,Z=K?{}:null;let T;if(E){const e=[];f.walkAtRules("value",n=>{const{params:t}=n,r=t.split(":")[0].trim();e.push(r)}),T=new RegExp(`^-?(:?${e.join("|")})$`)}e.forEach(e=>{let o=e;function s(n,t,o,s=!1){const{value:a,prop:l}=n,c=o||a;let g=!1,v=!1,O=!1,V=!1;if(E&&d(E,e)&&(g=F.test(c)||T.test(c)),k&&!g&&d(k,e)&&(v=w.test(c)),s&&(!E||E&&!g)&&(!k||k&&!v)&&!0!==((e,n)=>j.test(e)&&"transparent"===n||F.test(n)||w.test(n)||r(e,n))(t,o))return!1;if(S&&(!g||!v)){let n=z[e];if(!n){const t=h(S,e);t&&(n=new RegExp(`^${t.join("$|^")}$`),z[e]=n)}n&&(O=n.test(c))}if(K&&(!g||!v||!O)){let n=Z[e];if(!n){const t=b(K,e);t&&(n=t.map(A),Z[e]=n)}n&&(V=n.filter(e=>e.test(c)).length>0)}if(!(g||v||O||V)){const r=function(e,n){const{ignoreVariables:t,ignoreFunctions:r,ignoreKeywords:o,ignoreValues:s}=e,i=[];return t&&i.push("variable"),r&&i.push("function"),o&&h(o,n)&&i.push("keyword"),-1===i.indexOf("keyword")&&s&&b(s,n)&&i.push("keyword"),i}($,e);if(u.fix&&!P&&q)try{const e=q(n,{validVar:g,validFunc:v,validKeyword:O,validValue:V,longhandProp:t,longhandValue:o},f,$);e&&(n.value=e)}catch(e){const{raws:t}=n,r=n.source.start;x.report({ruleName:i,result:p,node:n,line:r.line,column:r.column+l.length+t.between.length,message:m.failedToFix(e,c,l)})}else{const{raws:e}=n,t=n.source.start;x.report({ruleName:i,result:p,node:n,line:t.line,column:t.column+l.length+e.between.length,message:R?m.customExpected(y(r),c,l,R):m.expected(y(r),c,l)})}return!0}return!1}O(o)&&(o=V(o)),f.walkDecls(function(e){const{value:r,prop:i}=e;if(v.test(i))return;const a=M&&n.isShorthand(i);if(i===o||!a&&o instanceof RegExp&&o.test(i)){const n=t.space(r);if(n.length>1){let t=!1;n.forEach(n=>{t||(t=s(e,i,n))})}else s(e)}else if(a){const t=n.expand(i,r,N);let a=!1;Object.keys(t).forEach(n=>{const r=t[n];!a&&(n===o||o instanceof RegExp&&o.test(n))&&(a=s(e,n,r,!0))})}})})};E.primaryOptionArray=!0,E.ruleName=i,E.messages=m;const k=e.createPlugin(i,E);export default k;export{m as messages,i as ruleName};
|
|
//# sourceMappingURL=index.modern.js.map
|