Security News
Fluent Assertions Faces Backlash After Abandoning Open Source Licensing
Fluent Assertions is facing backlash after dropping the Apache license for a commercial model, leaving users blindsided and questioning contributor rights.
stylelint-rule-creator
Advanced tools
This is not an official stylelint package.
Create custom stylelint rules with less boilerplate.
This package greatly reduces the complexity of creating custom stylelint rules. All that is needed is calling a single function to generate a rule that is testable and directly exportable to stylelint as a plugin. All the necessary types are also included to help you keep everything type safe.
npm install stylelint-rule-creator
This is all you need in order to create a rule:
import {createRule} from 'stylelint-rule-creator';
export const myExampleRule = createRule({
ruleName: 'my-plugin-name/my-rule-name',
messages: {
myMessageName: (messageInput: string) => `My message example: ${messageInput}`,
},
ruleCallback: (report, messages, {primaryOption, root}) => {
if (!primaryOption) {
return;
}
root.walkDecls(decl => {
if (decl.prop === 'visibility') {
report({
message: messages.myMessageName(decl.value),
node: decl,
word: decl.value,
});
}
});
},
});
For a concrete, in-use example see this rule creation test file.
This package also exports the functionality of the stylelint-jest-rule-tester
package.
In a central file somewhere, create your testRule
function by calling getTestRuleFunction
with a reference to your plugin's main file:
import {getTestRuleFunction} from 'stylelint-rule-creator';
export const testRule = getTestRuleFunction({
// a plugin must be supplied so that stylelint can find the rule(s) you want to test
linterOptions: {config: {plugins: ['./dist/index.js']}},
});
In this example, dist/index.js
should be the file which is exporting your rules as its default export. See this plugin test file as an example of this.
Then, in your rule's test file, import and call testRule
like so:
import {exampleRule} from './example.rule';
import {testRule} from '.';
testRule({
ruleName: exampleRule.name,
ruleOptions: [true],
fix: false,
accept: [
{
// this code should pass the rule
code: 'div { color: blue }',
},
],
reject: [
{
// this code should fail the rule
code: 'div { color: blue; visibility: hidden; }',
message: exampleRule.messages.myMessageName('hidden'),
},
],
});
For an actual example of this in use, see this rule test file.
FAQs
Create custom stylelint rules with less boilerplate.
We found that stylelint-rule-creator demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
Fluent Assertions is facing backlash after dropping the Apache license for a commercial model, leaving users blindsided and questioning contributor rights.
Research
Security News
Socket researchers uncover the risks of a malicious Python package targeting Discord developers.
Security News
The UK is proposing a bold ban on ransomware payments by public entities to disrupt cybercrime, protect critical services, and lead global cybersecurity efforts.