How to use the prettier-linter-helpers.generateDifferences function in prettier-linter-helpers

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 ember-template-lint / ember-template-lint-plugin-prettier / lib / rules / prettier.js View on Github external
if (err.loc) {
              message = message.replace(/ \(\d+:\d+\)$/, "");
            }

            this.log({
              message,
              line: node.loc && node.loc.start.line,
              column: node.loc && node.loc.start.column,
              source
            });

            return;
          }

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

            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(

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