Skip to content

Commit

Permalink
Merge pull request #19 from pazams/pazams/increase-test-coverage
Browse files Browse the repository at this point in the history
Increase test coverage
  • Loading branch information
pazams authored Jul 26, 2024
2 parents 99a32b7 + 027db3a commit 5d3d378
Show file tree
Hide file tree
Showing 3 changed files with 289 additions and 1,899 deletions.
26 changes: 14 additions & 12 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,12 +23,10 @@ const isScopeApplied = (selector, scope) => {
* @param {string} scope
*/
const isValidScope = scope => {
if (scope){
return scope.indexOf(',') === -1;
} else {
if (!scope){
return false;
}

return scope.indexOf(',') === -1;
}

/**
Expand All @@ -37,28 +35,32 @@ const isValidScope = scope => {
* @param {Rule} rule
*/
const isRuleScopable = rule => {

if(rule.parent.type !== 'root') {
return rule.parent.type === 'atrule' && conditionalGroupRules.indexOf(rule.parent.name) > -1;
} else {
return true;
}

}

const scopify = (options) => {

let scope;

/**
* extract the scope from the input given by caller
*
* @param {string | Record<string, string>} options
*/
const extractScope = (options) => {
if (typeof options === 'string') {
scope = options;
return options;
} else if (isObject(options) && options.scope) {
scope = options.scope
return options.scope
}
return null;
}

const scopify = (options) => {
return {
postcssPlugin: 'postcss-scopify',
Once (root, { result }) {
const scope = extractScope(options);
// guard statment- allow only valid scopes
if(!isValidScope(scope)){
throw root.error('invalid scope', { plugin: 'postcss-scopify' });
Expand Down
Loading

0 comments on commit 5d3d378

Please sign in to comment.