How to use the stylelint.formatters 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 exogen / jest-styled-components-stylelint / src / index.js View on Github external
let filterWarning

      // Prepare input for stylelint.
      const transformResult = preprocess(selector, code)
      if (Array.isArray(transformResult)) {
        code = transformResult[0]
        filterWarning = transformResult[1]
      } else {
        code = transformResult
      }

      const options = Object.assign({ code }, lintOptions)

      // Wrap or create formatter.
      if (typeof options.formatter === 'string') {
        const formatter = stylelint.formatters[options.formatter]
        if (formatter) {
          options.formatter = wrapFormatter(formatter, filterWarning)
        }
      } else if (options.formatter) {
        options.formatter = wrapFormatter(options.formatter, filterWarning)
      } else {
        const formatter = createFormatter(
          selector,
          css,
          component,
          formatterOptions
        )
        options.formatter = wrapFormatter(formatter, filterWarning)
      }

      return stylelint.lint(options).then(result => {
github learningequality / kolibri / frontend_build / src / prettier-frontend.js View on Github external
/* eslint-disable no-console */
const fs = require('fs');
const path = require('path');
const prettier = require('prettier');
const compiler = require('vue-template-compiler');
const ESLinter = require('eslint').Linter;
const HTMLHint = require('htmlhint').HTMLHint;
const esLintFormatter = require('eslint/lib/formatters/stylish');
const stylelint = require('stylelint');
const colors = require('colors');
const chokidar = require('chokidar');
const stylelintFormatter = require('stylelint').formatters.string;
const esLintConfig = require('../../.eslintrc.js');
const htmlHintConfig = require('../../.htmlhintrc.js');
const stylelintConfig = require('../../.stylelintrc.js');
const logging = require('./logging');

require('./htmlhint_custom');

logging.prefix = 'Kolibri linter: ';

const esLinter = new ESLinter();
const errorOrChange = 1;
const noChange = 0;
/*
  Modifications to match our component linting conventions.
  Surround style and script blocks by 2 new lines and ident.
*/
github learningequality / kolibri / packages / kolibri-tools / lib / lint.js View on Github external
const fs = require('fs');
const path = require('path');
const prettier = require('prettier');
const compiler = require('vue-template-compiler');
const ESLintCLIEngine = require('eslint').CLIEngine;
const HTMLHint = require('htmlhint').HTMLHint;
const esLintFormatter = require('eslint/lib/cli-engine/formatters/stylish');
const stylelint = require('stylelint');
const colors = require('colors');
const stylelintFormatter = require('stylelint').formatters.string;

require('./htmlhint_custom');

// check for host project's linting configs, otherwise use defaults
let hostProjectDir = process.cwd();

let esLintConfig;
try {
  esLintConfig = require(`${hostProjectDir}/.eslintrc.js`);
} catch (e) {
  esLintConfig = require('../.eslintrc.js');
}

let stylelintConfig;
try {
  stylelintConfig = require(`${hostProjectDir}/.stylelintrc.js`);
github senntyou / lila / cmd / util / stylelint.js View on Github external
const path = require('path');
const stylelint = require('stylelint');

const formatter = stylelint.formatters.string;

const argv = require('../../data/argv');

const projectConfig = require('../../project_config');

const modules = argv.module.split(',');
const moduleDirs = modules.map(moduleName => {
  if (moduleName === '*' || moduleName === 'all') return '';
  else if (moduleName.slice(-2) === '/*') return moduleName.slice(0, -2);
  else return moduleName;
});
const moduleFiles = [];
const extensions = ['css', 'less', 'scss', 'sass'];
moduleDirs.forEach(dir => {
  extensions.forEach(ext => {
    moduleFiles.push(path.join(projectConfig.buildPaths.src.dir, dir, '**/*.' + ext));
github alan-agius4 / speedy-build-angular / src / index.ts View on Github external
configBasedir: systemRoot,
		files: getFilesToLint(systemRoot, options),
		fix
	});

	if (!silent) {
		if (result.errored) {
			context.logger.error("Lint errors found in the listed files.");
		} else {
			context.logger.info("All files pass linting.");
		}

		const errored = result.results.filter(x => x.errored);

		if (errored.length) {
			context.logger.info(stylelint.formatters.string(errored));
		}
	}

	return {
		success: force || !result.errored
	};
}
github dojo / cli-build-app / src / base.config.ts View on Github external
formatter: (results: any) => {
					return stylelint.formatters
						.string(results)
						.replace(/selector-max-type|selector-max-universal/g, 'css-modules')
						.replace(
							/to have no more than (\d*) type selectors/g,
							'to not contain element selectors due to unsafe isolation'
						)
						.replace(
							/to have no more than (\d*) universal selectors/g,
							'to not contain universal (*) selectors due to unsafe isolation'
						);
				},
				context: srcPath,
github cascornelissen / stylelint-bare-webpack-plugin / lib / index.js View on Github external
formatter: (() => {
                if ( get(stylelint, 'formatters.string') ) {
                    return stylelint.formatters.string;
                } else if ( moduleAvailable('stylelint/dist/formatters/stringFormatter') ) {
                    return require('stylelint/dist/formatters/stringFormatter').default;
                }
            })()
        }, options);
github x-orpheus / elint / src / workers / stylelint / formatter.js View on Github external
'use strict'

const stringFormatter = require('stylelint').formatters.string

/**
 * @typedef {Object} StylelintResultWarning
 *
 * @property {string} severity 错误级别
 */

/**
 * @typedef {Object} StylelintResult
 *
 * @property {StylelintResultWarning[]} warnings 异常信息
 */

/**
 * 自定义 stylelint formatter
 *