This repository was archived by the owner on Apr 14, 2022. It is now read-only.
Repository navigation
Check if #noqa is present in line before adding diagnostic #1272
Merged
Cameron Trando (CTrando)
merged 14 commits into
microsoft:master
from
CTrando:scratch/NoQAImpl
Jul 15, 2019
Merged
Changes from all commits
Commits
Show all changes
14 commits
Select commit
Hold shift + click to select a range
a3e505d
Adding NoQA and tests
CTrando 6d4e7df
Minor changes
CTrando c7439d5
Checking for noqa in the comment, not for #noqa
CTrando df5d682
Moved method to extension and removed test that did not contribute an…
CTrando e7dd636
Changing loop style, handling null better
CTrando cd707ca
Shifting logic around
CTrando 9bec166
Doing binary search correctly on comment locations and adding test to…
CTrando ecd7827
Shortening up logic
CTrando a1bef03
getting rid of cast
CTrando 4c77f6f
Adding cast back, is necessary for GetLine method
CTrando 3bc3413
Moving to extension approach
CTrando e1e424c
Moving things around
CTrando 483fbd2
Fixing issues with having a space or tab in front of #noqa
CTrando b23e59d
Returning empty string on no comment
CTrando File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -241,8 +241,7 @@ public string Content { | |
| return _buffer.Text; | ||
| } | ||
| } | ||
| } | ||
|
|
||
| } | ||
| #endregion | ||
|
|
||
| #region Parsing | ||
|
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,120 @@ | ||
| using System.Collections.Generic; | ||
| using System.Linq; | ||
| using System.Threading.Tasks; | ||
| using FluentAssertions; | ||
| using Microsoft.Python.Analysis.Analyzer; | ||
| using Microsoft.Python.Analysis.Core.Interpreter; | ||
| using Microsoft.Python.Analysis.Diagnostics; | ||
| using Microsoft.Python.Analysis.Tests.FluentAssertions; | ||
| using Microsoft.Python.Core; | ||
| using Microsoft.Python.Parsing; | ||
| using Microsoft.Python.Parsing.Tests; | ||
| using Microsoft.VisualStudio.TestTools.UnitTesting; | ||
| using TestUtilities; | ||
| using ErrorCodes = Microsoft.Python.Analysis.Diagnostics.ErrorCodes; | ||
|
|
||
| namespace Microsoft.Python.Analysis.Tests { | ||
|
|
||
| [TestClass] | ||
| public class LintNoQATests : AnalysisTestBase { | ||
|
|
||
| public const string GenericSetup = @" | ||
| from typing import Generic, TypeVar | ||
| T = TypeVar('T', int, str) | ||
| T1 = TypeVar('T1', int, str) | ||
|
|
||
| _X = TypeVar('_X', str, int) | ||
| _T = _X | ||
| "; | ||
|
|
||
| public TestContext TestContext { get; set; } | ||
|
|
||
| [TestInitialize] | ||
| public void TestInitialize() | ||
| => TestEnvironmentImpl.TestInitialize($"{TestContext.FullyQualifiedTestClassName}.{TestContext.TestName}"); | ||
|
|
||
| [TestCleanup] | ||
| public void Cleanup() => TestEnvironmentImpl.TestCleanup(); | ||
|
|
||
| [DataRow("x = Generic[T, str] #noqa")] | ||
| [DataRow("x = Generic[T, T] #noqa ")] | ||
| [DataTestMethod, Priority(0)] | ||
| public async Task IgnoreGenerics(string decl) { | ||
| string code = GenericSetup + decl; | ||
|
|
||
| var analysis = await GetAnalysisAsync(code); | ||
| analysis.Diagnostics.Should().BeEmpty(); | ||
| } | ||
|
|
||
| [DataRow("x = 'str' + 5 #noqa")] | ||
| [DataRow("x = float(1) * 'str' #noqa")] | ||
| [DataTestMethod, Priority(0)] | ||
| public async Task IgnoreBadBinaryOp(string code) { | ||
| var analysis = await GetAnalysisAsync(code); | ||
| analysis.Diagnostics.Should().BeEmpty(); | ||
| } | ||
|
|
||
| [DataRow("x = 'str' + 5 # noqa")] | ||
| [DataRow("x = float(1) * 'str' # noqa")] | ||
| [DataTestMethod, Priority(0)] | ||
| public async Task IgnoreNoQAWithSpace(string code) { | ||
| var analysis = await GetAnalysisAsync(code); | ||
| analysis.Diagnostics.Should().BeEmpty(); | ||
| } | ||
|
|
||
| [DataRow("x = 'str' + 5 # noqa")] | ||
| [DataRow("x = float(1) * 'str' # noqa")] | ||
| [DataTestMethod, Priority(0)] | ||
| public async Task IgnoreNoQAWithTab(string code) { | ||
| var analysis = await GetAnalysisAsync(code); | ||
| analysis.Diagnostics.Should().BeEmpty(); | ||
| } | ||
|
|
||
| [DataRow("x = 'str' + 5 #NOQA")] | ||
| [DataRow("x = float(1) * 'str' # NOQA")] | ||
| [DataRow("x = float(1) * 'str' # NOQA")] | ||
| [DataTestMethod, Priority(0)] | ||
| public async Task IgnoreNoQAUppercase(string code) { | ||
| var analysis = await GetAnalysisAsync(code); | ||
| analysis.Diagnostics.Should().BeEmpty(); | ||
| } | ||
|
|
||
| [TestMethod, Priority(0)] | ||
| public async Task VarNamedNoQAStillGivesDiagnostic() { | ||
| const string code = @" | ||
| noqa = 1 + 'str' | ||
| "; | ||
| var analysis = await GetAnalysisAsync(code); | ||
| analysis.Diagnostics.Should().HaveCount(1); | ||
|
|
||
| var diagnostic = analysis.Diagnostics.ElementAt(0); | ||
| diagnostic.ErrorCode.Should().Be(ErrorCodes.UnsupportedOperandType); | ||
| diagnostic.Message.Should().Be(Resources.UnsupporedOperandType.FormatInvariant("+", "int", "str")); | ||
| diagnostic.SourceSpan.Should().Be(2, 8, 2, 17); | ||
| diagnostic.Severity.Should().Be(Severity.Error); | ||
| } | ||
|
|
||
| [DataRow("x = y #noqa")] | ||
| [DataRow("x = z + 2 #noqa")] | ||
| [DataTestMethod, Priority(0)] | ||
| public async Task IgnoreUndefinedVar(string code) { | ||
| var d = await LintAsync(code); | ||
| d.Should().BeEmpty(); | ||
| } | ||
|
|
||
| [TestMethod, Priority(0)] | ||
| public async Task IgnoreMissingImport() { | ||
| string code = @" | ||
| from fake_module import User #noqa | ||
| "; | ||
| var analysis = await GetAnalysisAsync(code); | ||
| analysis.Diagnostics.Should().BeEmpty(); | ||
| } | ||
|
|
||
| private async Task<IReadOnlyList<DiagnosticsEntry>> LintAsync(string code, InterpreterConfiguration configuration = null) { | ||
| var analysis = await GetAnalysisAsync(code, configuration ?? PythonVersions.LatestAvailable3X); | ||
| var a = Services.GetService<IPythonAnalyzer>(); | ||
| return a.LintModule(analysis.Document); | ||
| } | ||
| } | ||
|
CTrando marked this conversation as resolved.
|
||
| } | ||
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.