Skip to content
This repository was archived by the owner on Apr 14, 2022. It is now read-only.

Match linter conditional walk to analysis #1999

Open
wants to merge 36 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
36 commits
Select commit Hold shift + click to select a range
c6a9c22
Remove stale reference
Sep 30, 2019
1360827
Merge branch 'master' of https://github.com/microsoft/python-language…
Oct 1, 2019
ccaaa02
Merge branch 'master' of https://github.com/microsoft/python-language…
Oct 4, 2019
da40dcc
Merge branch 'master' of https://github.com/microsoft/python-language…
Oct 4, 2019
c348ac3
Merge branch 'master' of https://github.com/microsoft/python-language…
Oct 5, 2019
53bc044
Merge branch 'master' of https://github.com/microsoft/python-language…
Oct 7, 2019
484a92a
Merge branch 'master' of https://github.com/MikhailArkhipov/python-la…
Oct 7, 2019
e6df3aa
Merge branch 'master' of https://github.com/microsoft/python-language…
Oct 8, 2019
1d289d8
Merge branch 'master' of https://github.com/microsoft/python-language…
Oct 8, 2019
126f355
Merge branch 'master' of https://github.com/microsoft/python-language…
Oct 12, 2019
7e715f3
Merge branch 'master' of https://github.com/microsoft/python-language…
Oct 25, 2019
32923a5
Merge branch 'master' of https://github.com/microsoft/python-language…
Oct 31, 2019
1b72f4b
Merge branch 'master' of https://github.com/microsoft/python-language…
Nov 2, 2019
f74d5b6
Merge branch 'master' of https://github.com/microsoft/python-language…
Nov 7, 2019
0b28fa4
Merge branch 'master' of https://github.com/microsoft/python-language…
Nov 12, 2019
6109ac7
Don't suppress LHS diagnostics on augmented assign
Nov 12, 2019
bcfc3b7
Revert "Don't suppress LHS diagnostics on augmented assign"
Nov 12, 2019
dc286b8
Merge branch 'master' of https://github.com/microsoft/python-language…
Nov 13, 2019
0aab4f5
Merge branch 'master' of https://github.com/microsoft/python-language…
Nov 16, 2019
b953ce7
Merge branch 'master' of https://github.com/microsoft/python-language…
Nov 18, 2019
aef887d
Merge branch 'master' of https://github.com/microsoft/python-language…
Dec 10, 2019
b97b641
Merge branch 'master' of https://github.com/microsoft/python-language…
Dec 11, 2019
c16646d
Escape [ and ]
Dec 13, 2019
f3e08d5
Merge branch 'master' of https://github.com/MikhailArkhipov/python-la…
Dec 13, 2019
5700642
PR feedback
Dec 13, 2019
1d091db
Merge branch 'master' of https://github.com/microsoft/python-language…
Dec 13, 2019
b8c3615
Merge branch 'master' of https://github.com/microsoft/python-language…
Dec 16, 2019
6a88069
Merge branch 'master' of https://github.com/microsoft/python-language…
Jan 28, 2020
078c975
Merge branch 'master' of https://github.com/microsoft/python-language…
Mar 12, 2020
ac07704
Merge master
Mar 18, 2020
40be62b
Merge branch 'master' of https://github.com/microsoft/python-language…
Mar 19, 2020
b384853
Merge branch 'master' of https://github.com/microsoft/python-language…
Mar 20, 2020
a0632ef
Merge branch 'master' of https://github.com/microsoft/python-language…
Mar 26, 2020
c9b72bd
Merge branch 'master' of https://github.com/microsoft/python-language…
Mar 26, 2020
1e8291b
Merge branch 'master' of https://github.com/microsoft/python-language…
Apr 17, 2020
905da02
Match if walk in linter to analysis
Apr 17, 2020
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,10 @@
using System.Collections.Generic;
using System.Linq;
using Microsoft.Python.Analysis.Analyzer;
using Microsoft.Python.Analysis.Analyzer.Handlers;
using Microsoft.Python.Analysis.Types;
using Microsoft.Python.Core;
using Microsoft.Python.Core.OS;
using Microsoft.Python.Core.Text;
using Microsoft.Python.Parsing.Ast;
using Microsoft.Python.Parsing.Extensions;
Expand Down Expand Up @@ -55,6 +57,7 @@ public override bool Walk(ListComprehension node) {
return false;
}


public override bool Walk(SetComprehension node) {
node.Walk(new ComprehensionWalker(_walker, _localNames, _localNameExpressions));
return false;
Expand All @@ -75,6 +78,11 @@ public override bool Walk(NamedExpression node) {
return false;
}

public override bool Walk(IfStatement node)
=> node.WalkIfWithSystemConditions(_walker,
_walker.Analysis.Document.Interpreter.LanguageVersion,
_walker.Services.GetService<IOSPlatform>());

public override bool Walk(NameExpression node) {
if (_localNames?.Contains(node.Name) == true) {
return false;
Expand Down
16 changes: 16 additions & 0 deletions src/Analysis/Ast/Test/LintUndefinedVarsTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -832,6 +832,22 @@ public async Task AugmentedAssignToUndefined() {
d[0].SourceSpan.Should().Be(2, 1, 2, 2);
}

[TestMethod, Priority(0)]
public async Task PlatformSpecific() {
const string code = @"
import sys

if sys.platform == 'linux':
aVariable='Hello Linux'
print(aVariable)

else:
aVariable = 'Hello Other''
print(aVariable)
";
var d = await LintAsync(code);
d.Should().BeEmpty();
}

private async Task<IReadOnlyList<DiagnosticsEntry>> LintAsync(string code, InterpreterConfiguration configuration = null) {
var analysis = await GetAnalysisAsync(code, configuration ?? PythonVersions.LatestAvailable3X);
Expand Down