Skip to content

Commit

Permalink
Removed shebang handling code which is now unnecessary since yamllint…
Browse files Browse the repository at this point in the history
… 1.27.1
  • Loading branch information
tamere-allo-peter committed Aug 1, 2022
1 parent 3e27eed commit f0dcb91
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 19 deletions.
2 changes: 1 addition & 1 deletion setup.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ packages = find:
python_requires = >=3.6
include_package_data = True
install_requires =
yamllint >= 1.26.3
yamllint >= 1.27.1
setuptools

[options.package_data]
Expand Down
21 changes: 3 additions & 18 deletions yamlfixer/filefixer.py
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,6 @@ def __init__(self, arguments, filename):
super().__init__(arguments)
self.filename = filename
self.loffset = self.coffset = 0
self.shebang = ''
self.incontents = None
self.lines = []
self.issues = self.issueshandled = 0
Expand All @@ -68,20 +67,6 @@ def _canonicalizeproblems(self, linteroutput):
coltofix = colstofix.setdefault(int(colnumber), [])
coltofix.append(msg)
self.issues += 1

# If there's a shebang line we ignore it and any problem reported on it
if (self.incontents is not None) and self.incontents.startswith('#!'):
eolpos = self.incontents.find('\n') + 1
self.shebang = self.incontents[:eolpos]
self.incontents = self.incontents[eolpos:]
try:
del problemlines[1]
self.issues -= 1
except KeyError:
pass # No problem reported on shebang line by yamllint
# This line won't ever see the fixer so all subsequent lines must be offset by -1
self.loffset = -1

return problemlines

def lint(self, content):
Expand Down Expand Up @@ -131,7 +116,7 @@ def load(self):
def diff(self, finalcontent):
"""Return a unified diff of original content to final one."""
differences = []
original = (self.shebang + (self.incontents or '')).splitlines(keepends=True)
original = (self.incontents or '').splitlines(keepends=True)
final = finalcontent.splitlines(keepends=True)
if original != final:
relbefore = f'"{self.filename}"'
Expand Down Expand Up @@ -159,11 +144,11 @@ def dump(self, outcontents):
retcode = FIX_SKIPPED
else:
retcode = FIX_MODIFIED
finaloutput = self.shebang + (outcontents or '')
finaloutput = outcontents or ''
if self.arguments.nochange:
# We don't want to modify anything
if self.filename == '-': # Always dump original input to stdout in this case
sys.stdout.write(self.shebang + (self.incontents or ''))
sys.stdout.write(self.incontents or '')
sys.stdout.flush()
else:
# It seems we really want to fix things.
Expand Down

0 comments on commit f0dcb91

Please sign in to comment.