How to use prettier-linter-helpers - 10 common examples

To help you get started, we’ve selected a few prettier-linter-helpers 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 protofire / solhint / lib / rules / miscellaneous / prettier.js View on Github external
enterSourceUnit(ctx) {
    try {
      // Check for optional dependencies with the try catch
      // Prettier is expensive to load, so only load it if needed.
      const prettier = require('prettier')

      const formatted = prettier.format(this.inputSrc, {
        filepath: this.fileName,
        plugins: ['prettier-plugin-solidity']
      })

      const differences = generateDifferences(this.inputSrc, formatted)

      differences.forEach(difference => {
        let loc = null
        switch (difference.operation) {
          case INSERT:
            loc = getLocFromIndex(this.inputSrc, difference.offset)
            this.errorAt(loc.line, loc.column, `Insert ${showInvisibles(difference.insertText)}`)
            break
          case DELETE:
            loc = getLocFromIndex(this.inputSrc, difference.offset)
            this.errorAt(loc.line, loc.column, `Delete ${showInvisibles(difference.deleteText)}`)
            break
          case REPLACE:
            loc = getLocFromIndex(this.inputSrc, difference.offset)
            this.errorAt(
              loc.line,
github prettier / stylelint-prettier / stylelint-prettier.js View on Github external
message,
          node: root,
          index: getIndexFromLoc(source, err.loc.start),
        });

        return;
      }

      // Everything is the same. Nothing to do here;
      if (source === prettierSource) {
        return;
      }

      // Otherwise let's generate some differences

      const differences = generateDifferences(source, prettierSource);

      const report = (message, index) => {
        return stylelint.utils.report({
          ruleName,
          result,
          message,
          node: root,
          index,
        });
      };

      if (context.fix) {
        // Fixes must be processed in reverse order, as an early delete shall
        // change the modification offsets for anything after it
        const rawData = differences.reverse().reduce((rawData, difference) => {
          let insertText = '';
github meteorlxy / eslint-plugin-prettier-vue / lib / rules / prettier / utils / prettier-differences.js View on Github external
// ESLint shows those pieces of information elsewhere already so
    // remove them from the message
    if (err.codeFrame) {
      message = message.replace(`\n${err.codeFrame}`, '')
    }
    if (err.loc) {
      message = message.replace(/ \(\d+:\d+\)$/, '')
    }

    context.report({ message, loc: err.loc })

    return
  }

  if (source !== prettierSource) {
    const differences = generateDifferences(source, prettierSource)

    differences.forEach(difference => {
      switch (difference.operation) {
        case INSERT:
          reportInsert(
            context,
            difference.offset + offset,
            difference.insertText
          )
          break
        case DELETE:
          reportDelete(
            context,
            difference.offset + offset,
            difference.deleteText
          )
github prettier / eslint-plugin-prettier / eslint-plugin-prettier.js View on Github external
// ESLint shows those pieces of information elsewhere already so
              // remove them from the message
              if (err.codeFrame) {
                message = message.replace(`\n${err.codeFrame}`, '');
              }
              if (err.loc) {
                message = message.replace(/ \(\d+:\d+\)$/, '');
              }

              context.report({ message, loc: err.loc });

              return;
            }

            if (source !== prettierSource) {
              const differences = generateDifferences(source, prettierSource);

              differences.forEach(difference => {
                switch (difference.operation) {
                  case INSERT:
                    reportInsert(
                      context,
                      difference.offset,
                      difference.insertText
                    );
                    break;
                  case DELETE:
                    reportDelete(
                      context,
                      difference.offset,
                      difference.deleteText
                    );
github prettier / eslint-plugin-prettier / eslint-plugin-prettier.js View on Github external
function reportInsert(context, offset, text) {
  const pos = context.getSourceCode().getLocFromIndex(offset);
  const range = [offset, offset];
  context.report({
    message: 'Insert `{{ code }}`',
    data: { code: showInvisibles(text) },
    loc: { start: pos, end: pos },
    fix(fixer) {
      return fixer.insertTextAfterRange(range, text);
    }
  });
}
github ember-template-lint / ember-template-lint-plugin-prettier / lib / rules / prettier.js View on Github external
differences.forEach(difference => {
              let message = "";
              let { line, column } = getLocFromIndex(
                difference.offset,
                this.source
              );

              switch (difference.operation) {
                case INSERT:
                  message = `Insert \`${showInvisibles(
                    difference.insertText
                  )}\``;
                  break;
                case DELETE:
                  message = `Delete \`${showInvisibles(
                    difference.deleteText
                  )}\``;
                  break;
                case REPLACE:
                  message = `Replace \`${showInvisibles(
                    difference.deleteText
                  )}\` with \`${difference.insertText}\``;
                  break;
              }

              this.log({ message, line, column, source });
            });
          }
github prettier / eslint-plugin-prettier / eslint-plugin-prettier.js View on Github external
function reportDelete(context, offset, text) {
  const start = context.getSourceCode().getLocFromIndex(offset);
  const end = context.getSourceCode().getLocFromIndex(offset + text.length);
  const range = [offset, offset + text.length];
  context.report({
    message: 'Delete `{{ code }}`',
    data: { code: showInvisibles(text) },
    loc: { start, end },
    fix(fixer) {
      return fixer.removeRange(range);
    }
  });
}
github prettier / stylelint-prettier / stylelint-prettier.js View on Github external
  insert: (code) => `Insert "${showInvisibles(code)}"`,
  delete: (code) => `Delete "${showInvisibles(code)}"`,
github prettier / eslint-plugin-prettier / eslint-plugin-prettier.js View on Github external
function reportReplace(context, offset, deleteText, insertText) {
  const start = context.getSourceCode().getLocFromIndex(offset);
  const end = context
    .getSourceCode()
    .getLocFromIndex(offset + deleteText.length);
  const range = [offset, offset + deleteText.length];
  context.report({
    message: 'Replace `{{ deleteCode }}` with `{{ insertCode }}`',
    data: {
      deleteCode: showInvisibles(deleteText),
      insertCode: showInvisibles(insertText)
    },
    loc: { start, end },
    fix(fixer) {
      return fixer.replaceTextRange(range, insertText);
    }
  });
}
github meteorlxy / eslint-plugin-prettier-vue / lib / rules / prettier / utils / report.js View on Github external
function reportDelete(context, offset, text) {
  const start = context.getSourceCode().getLocFromIndex(offset)
  const end = context.getSourceCode().getLocFromIndex(offset + text.length)
  const range = [offset, offset + text.length]
  context.report({
    message: 'Delete `{{ code }}`',
    data: { code: showInvisibles(text) },
    loc: { start, end },
    fix(fixer) {
      return fixer.removeRange(range)
    },
  })
}

prettier-linter-helpers

Utilities to help expose prettier output in linting tools

MIT
Latest version published 6 years ago

Package Health Score

70 / 100
Full package analysis

Similar packages