How to use stylelint

Comprehensive stylelint code examples:

How to use stylelint.formatters:

141
142
143
144
145
146
147
148
149
150
	configFile: '.stylelintrc.json',
	files: 'src/scss/**/*.scss',
	fix: true
})
	.then((data) => {
		const output = stylelint.formatters.string(data.results);

		if (output) console.log(output);
		finishLog('css-l');
		res(!!output);

How to use stylelint.resolveConfig:

29
30
31
32
33
34
35
36
37
38
39
40


	writeFixture(config, "eslint");
};


const calculateStylelint = async () => {
	const config = await stylelint.resolveConfig(path.join(root, "fixtures", "calculate.css"), {
		config: {
			extends: path.join(configPath, "stylelint.js"),
		},
		configBasedir: configPath,

How to use stylelint.createLinter:

54
55
56
57
58
59
60
61
62
63
// Initialize a stylelint linter for each style file type that we support
// Create them here so that we can reuse, rather than creating many many objects.
const styleLangs = ['scss', 'css', 'less'];
const styleLinters = {};
styleLangs.forEach(lang => {
  styleLinters[lang] = stylelint.createLinter({
    config: stylelintConfig,
    fix: true,
    configBasedir: path.resolve(__dirname, '..'),
  });

How to use stylelint.lint:

5
6
7
8
9
10
11
12
13
14
15
16


const createLinter = (testPath) => {
  return (options) => {
    const start = new Date();


    return stylelint.lint(options).then((data) => {
      if (data.errored) {
        return fail({
          start,
          end: new Date(),

How to use stylelint.createPlugin:

130
131
132
133
134
135
136
137


ruleFunction.ruleName = ruleName;
ruleFunction.messages = ruleMessages;
ruleFunction.meta = ruleMeta;


module.exports = stylelint.createPlugin(ruleName, ruleFunction);

How to use stylelint.utils:

23
24
25
26
27
28
29
30
31
32
33
34
let flexWrappingProps = { ...defaultFlexWrappingProps };
let isLastStyleDeclaration = false;


const ruleFunction = (_, options) => {
  return (root, result) => {
    const validOptions = stylelint.utils.validateOptions(result, ruleName);


    if (!validOptions) {
      return;
    }