]>
git.madduck.net Git - etc/vim.git/blobdiff - black.py
madduck's git repository
Every one of the projects in this repository is available at the canonical
URL git://git.madduck.net/madduck/pub/<projectpath> — see
each project's metadata for the exact URL.
All patches and comments are welcome. Please squash your changes to logical
commits before using git-format-patch and git-send-email to
patches@ git. madduck. net .
If you'd read over the Git project's submission guidelines and adhered to them,
I'd be especially grateful.
SSH access, as well as push access can be individually
arranged .
If you use my repositories frequently, consider adding the following
snippet to ~/.gitconfig and using the third clone URL listed for each
project:
[url "git://git.madduck.net/madduck/"]
insteadOf = madduck:
class CannotSplit(Exception):
"""A readable split that fits the allotted line length is impossible.
class CannotSplit(Exception):
"""A readable split that fits the allotted line length is impossible.
- Raised by `left_hand_split()` and `right_hand _split()`.
+ Raised by `left_hand_split()`, `right_hand_split()`, and `delimiter _split()`.
is_flag=True,
help=(
"Don't write back the files, just return the status. Return code 0 "
is_flag=True,
help=(
"Don't write back the files, just return the status. Return code 0 "
- "means nothing changed. Return code 1 means some files wer e "
+ "means nothing would change. Return code 1 means some files would b e "
"reformatted. Return code 123 means there was an internal error."
),
)
"reformatted. Return code 123 means there was an internal error."
),
)
ctx.exit(0)
elif len(sources) == 1:
p = sources[0]
ctx.exit(0)
elif len(sources) == 1:
p = sources[0]
+ report = Report(check=check )
try:
if not p.is_file() and str(p) == '-':
changed = format_stdin_to_stdout(
try:
if not p.is_file() and str(p) == '-':
changed = format_stdin_to_stdout(
- if closing.type == token.RSQB or closing.type == token.R BRACE:
+ if closing.type == token.RBRACE:
self.leaves.pop()
return True
self.leaves.pop()
return True
+ if closing.type == token.RSQB:
+ comma = self.leaves[-1]
+ if comma.parent and comma.parent.type == syms.listmaker:
+ self.leaves.pop()
+ return True
+
# For parens let's check if it's safe to remove the comma. If the
# trailing one is the only one, we might mistakenly change a tuple
# into a different type by removing the comma.
# For parens let's check if it's safe to remove the comma. If the
# trailing one is the only one, we might mistakenly change a tuple
# into a different type by removing the comma.
@dataclass
class Report:
"""Provides a reformatting counter."""
@dataclass
class Report:
"""Provides a reformatting counter."""
change_count: int = 0
same_count: int = 0
failure_count: int = 0
change_count: int = 0
same_count: int = 0
failure_count: int = 0
def done(self, src: Path, changed: bool) -> None:
"""Increment the counter for successful reformatting. Write out a message."""
if changed:
def done(self, src: Path, changed: bool) -> None:
"""Increment the counter for successful reformatting. Write out a message."""
if changed:
- out(f'reformatted {src}')
+ reformatted = 'would reformat' if self.check else 'reformatted'
+ out(f'{reformatted} {src}')
self.change_count += 1
else:
out(f'{src} already well formatted, good job.', bold=False)
self.change_count += 1
else:
out(f'{src} already well formatted, good job.', bold=False)
if self.failure_count:
return 123
if self.failure_count:
return 123
- elif self.change_count:
+ elif self.change_count and self.check :
Use `click.unstyle` to remove colors.
"""
Use `click.unstyle` to remove colors.
"""
+ if self.check:
+ reformatted = "would be reformatted"
+ unchanged = "would be left unchanged"
+ failed = "would fail to reformat"
+ else:
+ reformatted = "reformatted"
+ unchanged = "left unchanged"
+ failed = "failed to reformat"
report = []
if self.change_count:
s = 's' if self.change_count > 1 else ''
report.append(
report = []
if self.change_count:
s = 's' if self.change_count > 1 else ''
report.append(
- click.style(f'{self.change_count} file{s} reformatted ', bold=True)
+ click.style(f'{self.change_count} file{s} {reformatted} ', bold=True)
)
if self.same_count:
s = 's' if self.same_count > 1 else ''
)
if self.same_count:
s = 's' if self.same_count > 1 else ''
- report.append(f'{self.same_count} file{s} left unchanged ')
+ report.append(f'{self.same_count} file{s} {unchanged} ')
if self.failure_count:
s = 's' if self.failure_count > 1 else ''
report.append(
if self.failure_count:
s = 's' if self.failure_count > 1 else ''
report.append(
- click.style(
- f'{self.failure_count} file{s} failed to reformat', fg='red'
- )
+ click.style(f'{self.failure_count} file{s} {failed}', fg='red')
)
return ', '.join(report) + '.'
)
return ', '.join(report) + '.'