From f5e2ca09484ed66956314c494eed83693f19644d Mon Sep 17 00:00:00 2001 From: Jin Suk Park Date: Wed, 21 Nov 2018 19:56:56 +0900 Subject: Add option to ignore comments --- isort/isort.py | 13 +++++++++---- isort/settings.py | 3 ++- 2 files changed, 11 insertions(+), 5 deletions(-) diff --git a/isort/isort.py b/isort/isort.py index cf22472a..0286c3dc 100644 --- a/isort/isort.py +++ b/isort/isort.py @@ -270,11 +270,16 @@ class SortImports(object): def _add_comments(self, comments, original_string=""): """ - Returns a string with comments added + Returns a string with comments added if ignore_comments is not set. """ - return comments and "{0}{1} {2}".format(self._strip_comments(original_string)[0], - self.config['comment_prefix'], - "; ".join(comments)) or original_string + + if not self.config['ignore_comments']: + return comments and "{0}{1} {2}".format(self._strip_comments(original_string)[0], + self.config['comment_prefix'], + "; ".join(comments)) or original_string + + return comments and self._strip_comments(original_string)[0] + def _wrap(self, line): """ diff --git a/isort/settings.py b/isort/settings.py index fa146b8c..3661ea19 100644 --- a/isort/settings.py +++ b/isort/settings.py @@ -138,7 +138,8 @@ default = {'force_to_top': [], 'show_diff': False, 'ignore_whitespace': False, 'no_lines_before': [], - 'no_inline_sort': False} + 'no_inline_sort': False, + 'ignore_comments': False} @lru_cache() -- cgit v1.2.1 From a539a88951b13cc75b80e7a2f914a2b726c2d0cc Mon Sep 17 00:00:00 2001 From: Timothy Edmund Crosley Date: Sun, 17 Feb 2019 18:29:54 -0800 Subject: Update settings.py --- isort/settings.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/isort/settings.py b/isort/settings.py index e8f98f5b..f6ef1c25 100644 --- a/isort/settings.py +++ b/isort/settings.py @@ -152,7 +152,7 @@ default = {'force_to_top': [], 'ignore_whitespace': False, 'no_lines_before': [], 'no_inline_sort': False, - 'ignore_comments': False + 'ignore_comments': False, 'safety_excludes': True} -- cgit v1.2.1 From 397b6443eac022294e180b7ca714403417855df7 Mon Sep 17 00:00:00 2001 From: Timothy Edmund Crosley Date: Sun, 17 Feb 2019 18:36:07 -0800 Subject: Update isort.py Remove extra new line --- isort/isort.py | 1 - 1 file changed, 1 deletion(-) diff --git a/isort/isort.py b/isort/isort.py index df5b50eb..970117f1 100644 --- a/isort/isort.py +++ b/isort/isort.py @@ -288,7 +288,6 @@ class SortImports(object): return comments and self._strip_comments(original_string)[0] - def _wrap(self, line): """ Returns an import wrapped to the specified line-length, if possible. -- cgit v1.2.1