
import subprocess


def _NeedsFormat(path):
  return subprocess.call(['dartfmt', '--set-exit-if-changed', '-n', path]) != 0


def _CheckDartFormat(input_api, output_api):
  files = [
      git_file.AbsoluteLocalPath()
      for git_file in input_api.AffectedTextFiles()
  ]
  unformatted_files = [
      path for path in files
      if path.endswith('.dart') and _NeedsFormat(path)
  ]
  if unformatted_files:
    escapedNewline = ' \\\n'
    return [
        output_api.PresubmitError(
            'File output does not match dartfmt.\n'
            'Fix these issues with:\n'
            'dartfmt -w%s%s' %
            (escapedNewline, escapedNewline.join(unformatted_files)))
    ]
  return []


def CommonChecks(input_api, output_api):
  return _CheckDartFormat(input_api, output_api)


CheckChangeOnCommit = CommonChecks
CheckChangeOnUpload = CommonChecks


import subprocess


def _NeedsFormat(path):
  return subprocess.call(['dart', 'format', '--set-exit-if-changed',
                          '--output','none', path]) != 0


def _CheckDartFormat(input_api, output_api):
  files = [
      git_file.AbsoluteLocalPath()
      for git_file in input_api.AffectedTextFiles()
  ]
  unformatted_files = [
      path for path in files
      if path.endswith('.dart') and _NeedsFormat(path)
  ]
  if unformatted_files:
    escapedNewline = ' \\\n'
    return [
        output_api.PresubmitError(
            'File output does not match dartfmt.\n'
            'Fix these issues with:\n'
            'dart format%s%s' %
            (escapedNewline, escapedNewline.join(unformatted_files)))
    ]
  return []


def CommonChecks(input_api, output_api):
  return _CheckDartFormat(input_api, output_api)


CheckChangeOnCommit = CommonChecks
CheckChangeOnUpload = CommonChecks

Update presubmit to use 'dart format' command
Update presubmit to use 'dart format' command

The presubmit checks will then work with the Flutter SDK in the path.
This is the case when working on the Flutter web app current_results_ui.

Change-Id: I8a8d5db4454b57bc7936197032460e877037b386
Reviewed-on: https://dart-review.googlesource.com/c/dart_ci/+/191921
Reviewed-by: Alexander Thomas <29642742b6693024c89de8232f2e2542cf7eedf7@google.com>

  
  import subprocess
  
  
  def _NeedsFormat(path):
-   return subprocess.call(['dartfmt', '--set-exit-if-changed', '-n', path]) != 0
+   return subprocess.call(['dart', 'format', '--set-exit-if-changed',
+                           '--output','none', path]) != 0
  
  
  def _CheckDartFormat(input_api, output_api):
    files = [
        git_file.AbsoluteLocalPath()
        for git_file in input_api.AffectedTextFiles()
    ]
    unformatted_files = [
        path for path in files
        if path.endswith('.dart') and _NeedsFormat(path)
    ]
    if unformatted_files:
      escapedNewline = ' \\\n'
      return [
          output_api.PresubmitError(
              'File output does not match dartfmt.\n'
              'Fix these issues with:\n'
-             'dartfmt -w%s%s' %
+             'dart format%s%s' %
              (escapedNewline, escapedNewline.join(unformatted_files)))
      ]
    return []
  
  
  def CommonChecks(input_api, output_api):
    return _CheckDartFormat(input_api, output_api)
  
  
  CheckChangeOnCommit = CommonChecks
  CheckChangeOnUpload = CommonChecks
  
Update presubmit to use 'dart format' command
## Code Before:

import subprocess


def _NeedsFormat(path):
  return subprocess.call(['dartfmt', '--set-exit-if-changed', '-n', path]) != 0


def _CheckDartFormat(input_api, output_api):
  files = [
      git_file.AbsoluteLocalPath()
      for git_file in input_api.AffectedTextFiles()
  ]
  unformatted_files = [
      path for path in files
      if path.endswith('.dart') and _NeedsFormat(path)
  ]
  if unformatted_files:
    escapedNewline = ' \\\n'
    return [
        output_api.PresubmitError(
            'File output does not match dartfmt.\n'
            'Fix these issues with:\n'
            'dartfmt -w%s%s' %
            (escapedNewline, escapedNewline.join(unformatted_files)))
    ]
  return []


def CommonChecks(input_api, output_api):
  return _CheckDartFormat(input_api, output_api)


CheckChangeOnCommit = CommonChecks
CheckChangeOnUpload = CommonChecks

## Instruction:
Update presubmit to use 'dart format' command
## Code After:

import subprocess


def _NeedsFormat(path):
  return subprocess.call(['dart', 'format', '--set-exit-if-changed',
                          '--output','none', path]) != 0


def _CheckDartFormat(input_api, output_api):
  files = [
      git_file.AbsoluteLocalPath()
      for git_file in input_api.AffectedTextFiles()
  ]
  unformatted_files = [
      path for path in files
      if path.endswith('.dart') and _NeedsFormat(path)
  ]
  if unformatted_files:
    escapedNewline = ' \\\n'
    return [
        output_api.PresubmitError(
            'File output does not match dartfmt.\n'
            'Fix these issues with:\n'
            'dart format%s%s' %
            (escapedNewline, escapedNewline.join(unformatted_files)))
    ]
  return []


def CommonChecks(input_api, output_api):
  return _CheckDartFormat(input_api, output_api)


CheckChangeOnCommit = CommonChecks
CheckChangeOnUpload = CommonChecks
