diff --git a/.github/workflows/codeql.yml b/.github/workflows/codeql.yml new file mode 100644 index 0000000..8b6d5dc --- /dev/null +++ b/.github/workflows/codeql.yml @@ -0,0 +1,30 @@ +name: CodeQL + +on: + pull_request: + push: + schedule: + - cron: 0 0 * * 0 + +jobs: + codeql: + runs-on: ubuntu-latest + + steps: + - name: Checkout code + uses: actions/checkout@v2 + with: + fetch-depth: 2 + + - name: Checkout the head of the pull request instead + run: git checkout HEAD^2 + if: ${{ github.event_name == 'pull_request' }} + + - name: Initialize CodeQL + uses: github/codeql-action/init@v1 + + - name: Autobuild + uses: github/codeql-action/autobuild@v1 + + - name: Perform CodeQL analysis + uses: github/codeql-action/analyze@v1 diff --git a/.github/workflows/workflow.yml b/.github/workflows/workflow.yml new file mode 100644 index 0000000..81683cf --- /dev/null +++ b/.github/workflows/workflow.yml @@ -0,0 +1,32 @@ +name: Main workflow + +on: + - pull_request + - push + +jobs: + build: + strategy: + matrix: + os: + - ubuntu-latest + python-version: + - 2.7 + - 3.9 + + runs-on: ${{ matrix.os }} + + steps: + - name: Checkout code + uses: actions/checkout@v2 + + - name: Use Python ${{ matrix.python-version }} + uses: actions/setup-python@v2 + with: + python-version: ${{ matrix.python-version }} + + - name: Install packages + run: pip install -r dev-requirements.txt + + - name: Run tests + run: make test diff --git a/.travis.yml b/.travis.yml deleted file mode 100644 index 12ef4ad..0000000 --- a/.travis.yml +++ /dev/null @@ -1,10 +0,0 @@ -language: python - -python: - - "2.7" - - "3.6" - -install: - - "pip install -r dev-requirements.txt" -script: make test - diff --git a/Makefile b/Makefile index c0a0063..f3d2ac6 100644 --- a/Makefile +++ b/Makefile @@ -7,7 +7,13 @@ install: python setup.py develop pep8: - @flake8 codemod --ignore=F403 + # W503: Line break occurred before a binary operator + # W504: Line break occurred after a binary operator + # + # W503 conflicts with W504, but since W504 is now the recommended style, we + # intentionally ignore it. + # https://www.python.org/dev/peps/pep-0008/#should-a-line-break-before-or-after-a-binary-operator + @flake8 codemod --ignore=W503 release: test @python setup.py sdist upload diff --git a/README.md b/README.md index dbee93a..e6bda4e 100644 --- a/README.md +++ b/README.md @@ -3,7 +3,8 @@ codemod [![PyPI](https://img.shields.io/pypi/v/codemod.svg)](https://pypi.python.org/pypi/codemod) [![downloads](https://img.shields.io/pypi/dw/codemod.svg)](https://pypi.python.org/pypi/codemod) -[![Travis CI](http://img.shields.io/travis/facebook/codemod.svg)](https://travis-ci.org/facebook/codemod) +[![Main workflow](https://github.com/facebook/codemod/workflows/Main%20workflow/badge.svg?branch=master)](https://github.com/facebook/codemod/actions) +[![CodeQL](https://github.com/facebook/codemod/workflows/CodeQL/badge.svg?branch=master)](https://github.com/facebook/codemod/actions) [![Code Health](https://landscape.io/github/rochacbruno/codemod/master/landscape.svg?style=flat)](https://landscape.io/github/rochacbruno/codemod/master) diff --git a/codemod/base.py b/codemod/base.py index 7ddd456..9b4d761 100755 --- a/codemod/base.py +++ b/codemod/base.py @@ -262,11 +262,11 @@ def _ask_about_patch(patch, editor, default_no): if patch.new_lines is not None: if not yes_to_all: if default_no: - print('Accept change (y = yes, n = no [default], e = edit, ' + - 'A = yes to all, E = yes+edit, q = quit)? '), + print('Accept change (y = yes, n = no [default], e = edit, ' + + 'A = yes to all, E = yes+edit, q = quit)? '), else: - print('Accept change (y = yes [default], n = no, e = edit, ' + - 'A = yes to all, E = yes+edit, q = quit)? '), + print('Accept change (y = yes [default], n = no, e = edit, ' + + 'A = yes to all, E = yes+edit, q = quit)? '), p = _prompt('yneEAq', default=default_action) else: p = 'y' diff --git a/codemod/helpers.py b/codemod/helpers.py index f0070c4..4c32db0 100644 --- a/codemod/helpers.py +++ b/codemod/helpers.py @@ -84,9 +84,9 @@ def the_filter(path): return False if exclude_paths: for excluded in exclude_paths: - if (path.startswith(excluded) or - path.startswith('./' + excluded) or - fnmatch.fnmatch(path, excluded)): + if (path.startswith(excluded) + or path.startswith('./' + excluded) + or fnmatch.fnmatch(path, excluded)): return False return True return the_filter diff --git a/codemod/query.py b/codemod/query.py index 71129c3..91ce2b5 100644 --- a/codemod/query.py +++ b/codemod/query.py @@ -13,6 +13,7 @@ class Query(object): >>> Query(lambda x: None, start='profile.php:20').start_position Position('profile.php', 20) """ + def __init__(self, suggestor, start=None, @@ -22,7 +23,6 @@ def __init__(self, extensions=['php', 'phpt', 'js', 'css', 'rb', 'erb'] ), inc_extensionless=False): - """ @param suggestor A function that takes a list of lines and generates instances of Patch to suggest. @@ -138,9 +138,9 @@ def generate_patches(self): path_list = Query._sublist(path_list, start_pos.path, end_pos.path) path_list = ( path for path in path_list if - Query._path_looks_like_code(path) and - (self.path_filter(path)) or - (self.inc_extensionless and helpers.is_extensionless(path)) + Query._path_looks_like_code(path) + and (self.path_filter(path)) + or (self.inc_extensionless and helpers.is_extensionless(path)) ) for path in path_list: try: @@ -173,10 +173,9 @@ def _walk_directory(root_directory): of `root_directory`. """ - paths = [os.path.join(root, name) - for root, dirs, files in os.walk(root_directory) # noqa - for name in files] - paths.sort() + paths = sorted([os.path.join(root, name) + for root, dirs, files in os.walk(root_directory) + for name in files]) return paths @staticmethod @@ -208,8 +207,8 @@ def _path_looks_like_code(path): False """ return ( - '/.' not in path and - path[-1] != '~' and - not path.endswith('tags') and - not path.endswith('TAGS') + '/.' not in path + and path[-1] != '~' + and not path.endswith('tags') + and not path.endswith('TAGS') ) diff --git a/codemod/terminal_helper.py b/codemod/terminal_helper.py index 3443dc8..27635e9 100644 --- a/codemod/terminal_helper.py +++ b/codemod/terminal_helper.py @@ -14,10 +14,10 @@ def _unicode(s, encoding='utf-8'): - if type(s) == bytes: - return s.decode(encoding, 'ignore') - else: - return str(s) + if isinstance(s, bytes): + return s.decode(encoding, 'ignore') + else: + return str(s) def terminal_get_size(default_size=(25, 80)):