How to use the stylelint.lint function in stylelint

To help you get started, we’ve selected a few stylelint examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github YozhikM / stylelint-a11y / jest.setup.js View on Github external
if (testCase.column !== undefined) {
                expect(_.get(warning, 'column')).toBe(testCase.column);
              }

              if (!schema.fix) {
                return;
              }

              if (!testCase.fixed) {
                throw new Error(
                  'If using { fix: true } in test schema, all reject cases must have { fixed: .. }'
                );
              }

              // Check the fix
              return stylelint.lint(Object.assign({ fix: true }, options)).then(output2 => {
                const fixedCode = getOutputCss(output2);

                expect(fixedCode).toBe(testCase.fixed);
                expect(output2.results[0].warnings.length).toBe(0); // Ensure errors are not reported on fixed code
              });
            });
          });
github cahamilton / stylelint-config-property-sort-order-smacss / tests / index.js View on Github external
test("Stylelint configuration", function (t) {
  stylelint.lint({
    code: "a { color: red; top: 0; }",
    config,
  }).then(function (output) {
    const actual = output.results[0].warnings[0].text.trim();

    t.equal(actual, "Expected \"top\" to come before \"color\" (order/properties-order)")
    t.end()
  }).catch(function (err) {
    t.notOk(err)
    t.end()
  })
})
github primer / stylelint-config-primer / __tests__ / spacing.js View on Github external
it('fixes padding', () => {
      return stylelint
        .lint({
          code: dedent`
            .x { padding: 4px 8px 0; }
          `,
          config: configWithOptions(true, {verbose: true}),
          fix: true
        })
        .then(data => {
          expect(data).not.toHaveErrored()
          expect(data).toHaveWarningsLength(0)
          expect(data.output).toEqual(dedent`
            .x { padding: $spacer-1 $spacer-2 0; }
          `)
        })
    })
github WordPress-Coding-Standards / stylelint-config-wordpress / __tests__ / commenting.js View on Github external
beforeEach( () => {
		result = stylelint.lint({
			code: invalidCss,
			config,
		});
	});
github WordPress-Coding-Standards / stylelint-config-wordpress / __tests__ / vendor-prefixes.js View on Github external
beforeEach( () => {
		result = stylelint.lint({
			code: validCss,
			config,
		});
	});
github WordPress-Coding-Standards / stylelint-config-wordpress / __tests__ / structure.js View on Github external
beforeEach( () => {
		result = stylelint.lint({
			code: validCss,
			config,
		});
	});
github WordPress-Coding-Standards / stylelint-config-wordpress / __tests__ / index.js View on Github external
beforeEach( () => {
		result = stylelint.lint({
			code: invalidCss,
			config,
		});
	});
github 18F / stylelint-rules / bin / cli.js View on Github external
var files = program.args.pop();

if (!files) {
  console.log('You must supply the path of files to lint.');
  process.exit();
}

var formatter = program.formatter || 'verbose';
var ignoredFiles = program['ignore-files'];

if (ignoredFiles) {
  lintConfig['ignoreFiles'] = ignoredFiles;
}

stylelint.lint({
  files: files,
  config: program.config || lintConfig,
  configBasedir: path.join(__dirname, '../', './src'),
  syntax: program.syntax || 'scss',
  formatter: formatter
}).then(function(output) {
  var outputFormatter = formatters[formatter];
  console.log(outputFormatter && outputFormatter(output.results));
  if (output.errored) {
    process.exit(1);
  }
}).catch(function(err) {
  console.log(err);
  process.exit(1);
});
github VladimirIvanin / insales-uploader / lib / file-system / watch.js View on Github external
if (fileInfo.isMediaFile) {

        let isStyle = (_.indexOf(['.scss', '.css'], fileInfo.pathParse.ext) > -1);
        let isScripts = (_.indexOf(['.js'], fileInfo.pathParse.ext) > -1);
        let isScriptsLintUse = (_.indexOf(['.js'], fileInfo.pathParse.ext) > -1) && options.tools.esLint.use;
        let isStyleLintUse = (_.indexOf(['.scss', '.css'], fileInfo.pathParse.ext) > -1) && options.tools.stylelint.use;
        let isAutoprefixerUse = options.tools.autoprefixer.use;

        if (isStyle) {
          if (/#=/g.test(fileInfo.content.asset.content) || /\/=/g.test(fileInfo.content.asset.content)) {
            isAutoprefixerUse = false;
            isStyleLintUse = false;
          }

          if (isStyleLintUse) {
            stylelint.lint({
              code: fileInfo.content.asset.content,
              config: options.tools.stylelint.config,
              formatter: "string",
              syntax: "scss"
            }).then((data)  => {
              if (data.errored && data.output) {
                eventEmitter.emit('css:error', {
                  message: data.output
                });
                if (!options.tools.stylelint.stopOnFail) {
                  setQueueAsset(conf, state, fileInfo, {},debugMode);
                }
              }else{
                if (isAutoprefixerUse) {

                  postcss(postCssPlugins).process(fileInfo.content.asset.content, { syntax: syntax }).then(function (result) {
github commercetools / merchant-center-application-kit / packages / jest-stylelint-runner / run.js View on Github external
return options => {
    const start = new Date();

    return stylelint.lint(options).then(data => {
      if (data.errored) {
        return fail({
          start,
          end: new Date(),
          test: {
            path: testPath,
            errorMessage: data.output,
          },
        });
      }

      return pass({
        start,
        end: new Date(),
        test: { path: testPath },
      });