Skip to content

Commit c2a394c

Browse files
authored
[dotnet] Add linting support with configurable dotnet format (#16999)
* [build] update dotnet:format target to accept arguments * [build] limit dotnet:format to whitespace in format.sh and dotnet.rake * [dotnet] implement linting support * [dotnet] apply linting results
1 parent 2668969 commit c2a394c

File tree

4 files changed

+75
-62
lines changed

4 files changed

+75
-62
lines changed

dotnet/private/dotnet_format.bzl

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -52,10 +52,10 @@ DOTNET_DIR="$WORKSPACE_ROOT/dotnet"
5252
5353
cd "$DOTNET_DIR"
5454
55-
echo "Running dotnet format on all projects..."
55+
echo "Running dotnet format $@ on all projects..."
5656
find "$DOTNET_DIR/src" "$DOTNET_DIR/test" -name "*.csproj" 2>/dev/null | while read -r proj; do
5757
echo " Formatting $proj..."
58-
"$DOTNET" format "$proj" || exit 1
58+
"$DOTNET" format "$@" "$proj" || exit 1
5959
done || exit 1
6060
6161
echo "Done."
@@ -90,14 +90,14 @@ set DOTNET_DIR=%WORKSPACE_ROOT%\\dotnet
9090
9191
cd /d "%DOTNET_DIR%"
9292
93-
echo Running dotnet format on all projects...
93+
echo Running dotnet format %* on all projects...
9494
for /r "%DOTNET_DIR%\\src" %%%%p in (*.csproj) do (
9595
echo Formatting %%%%p...
96-
"%DOTNET%" format "%%%%p" || exit /b 1
96+
"%DOTNET%" format %* "%%%%p" || exit /b 1
9797
)
9898
for /r "%DOTNET_DIR%\\test" %%%%p in (*.csproj) do (
9999
echo Formatting %%%%p...
100-
"%DOTNET%" format "%%%%p" || exit /b 1
100+
"%DOTNET%" format %* "%%%%p" || exit /b 1
101101
)
102102
103103
echo Done.

dotnet/test/common/WebElementWrapper.cs

Lines changed: 54 additions & 55 deletions
Original file line numberDiff line numberDiff line change
@@ -20,79 +20,78 @@
2020
using System.Collections.ObjectModel;
2121
using System.Drawing;
2222

23-
namespace OpenQA.Selenium
23+
namespace OpenQA.Selenium;
24+
25+
public class WebElementWrapper(IWebElement element) : IWebElement, IWrapsElement
2426
{
25-
public class WebElementWrapper(IWebElement element) : IWebElement, IWrapsElement
26-
{
27-
public IWebElement WrappedElement { get; } = element;
27+
public IWebElement WrappedElement { get; } = element;
2828

29-
public string TagName => WrappedElement.TagName;
29+
public string TagName => WrappedElement.TagName;
3030

31-
public string Text => WrappedElement.Text;
31+
public string Text => WrappedElement.Text;
3232

33-
public bool Enabled => WrappedElement.Enabled;
33+
public bool Enabled => WrappedElement.Enabled;
3434

35-
public bool Selected => WrappedElement.Selected;
35+
public bool Selected => WrappedElement.Selected;
3636

37-
public Point Location => WrappedElement.Location;
37+
public Point Location => WrappedElement.Location;
3838

39-
public Size Size => WrappedElement.Size;
39+
public Size Size => WrappedElement.Size;
4040

41-
public bool Displayed => WrappedElement.Displayed;
41+
public bool Displayed => WrappedElement.Displayed;
4242

43-
public void Clear()
44-
{
45-
WrappedElement.Clear();
46-
}
43+
public void Clear()
44+
{
45+
WrappedElement.Clear();
46+
}
4747

48-
public void Click()
49-
{
50-
WrappedElement.Click();
51-
}
48+
public void Click()
49+
{
50+
WrappedElement.Click();
51+
}
5252

53-
public IWebElement FindElement(By by)
54-
{
55-
return WrappedElement.FindElement(by);
56-
}
53+
public IWebElement FindElement(By by)
54+
{
55+
return WrappedElement.FindElement(by);
56+
}
5757

58-
public ReadOnlyCollection<IWebElement> FindElements(By by)
59-
{
60-
return WrappedElement.FindElements(by);
61-
}
58+
public ReadOnlyCollection<IWebElement> FindElements(By by)
59+
{
60+
return WrappedElement.FindElements(by);
61+
}
6262

63-
public string GetAttribute(string attributeName)
64-
{
65-
return WrappedElement.GetAttribute(attributeName);
66-
}
63+
public string GetAttribute(string attributeName)
64+
{
65+
return WrappedElement.GetAttribute(attributeName);
66+
}
6767

68-
public string GetCssValue(string propertyName)
69-
{
70-
return WrappedElement.GetCssValue(propertyName);
71-
}
68+
public string GetCssValue(string propertyName)
69+
{
70+
return WrappedElement.GetCssValue(propertyName);
71+
}
7272

73-
public string GetDomAttribute(string attributeName)
74-
{
75-
return WrappedElement.GetDomAttribute(attributeName);
76-
}
73+
public string GetDomAttribute(string attributeName)
74+
{
75+
return WrappedElement.GetDomAttribute(attributeName);
76+
}
7777

78-
public string GetDomProperty(string propertyName)
79-
{
80-
return WrappedElement.GetDomProperty(propertyName);
81-
}
78+
public string GetDomProperty(string propertyName)
79+
{
80+
return WrappedElement.GetDomProperty(propertyName);
81+
}
8282

83-
public ISearchContext GetShadowRoot()
84-
{
85-
return WrappedElement.GetShadowRoot();
86-
}
83+
public ISearchContext GetShadowRoot()
84+
{
85+
return WrappedElement.GetShadowRoot();
86+
}
8787

88-
public void SendKeys(string text)
89-
{
90-
WrappedElement.SendKeys(text);
91-
}
88+
public void SendKeys(string text)
89+
{
90+
WrappedElement.SendKeys(text);
91+
}
9292

93-
public void Submit()
94-
{
95-
WrappedElement.Submit();
96-
}
93+
public void Submit()
94+
{
95+
WrappedElement.Submit();
9796
}
9897
}

rake_tasks/dotnet.rake

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -112,3 +112,17 @@ task :pin do
112112
'--output-folder', "#{Dir.pwd}/dotnet"],
113113
'@rules_dotnet//tools/paket2bazel:paket2bazel')
114114
end
115+
116+
desc 'Run .NET formatter (whitespace only)'
117+
task :format do |_task, arguments|
118+
raise ArgumentError, 'arguments not supported for this task' unless arguments.to_a.empty?
119+
120+
puts ' Running dotnet format whitespace...'
121+
Bazel.execute('run', ['--', 'whitespace'], '//dotnet:format')
122+
end
123+
124+
desc 'Run .NET linter (format + style + analyzers)'
125+
task :lint do |_task, arguments|
126+
puts ' Running dotnet format...'
127+
Bazel.execute('run', ['--'] + arguments.to_a, '//dotnet:format')
128+
end

scripts/format.sh

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,8 @@ echo " buildifier" >&2
1515
bazel run //:buildifier
1616

1717
section "Dotnet"
18-
echo " dotnet format" >&2
19-
bazel run //dotnet:format
18+
echo " dotnet format whitespace" >&2
19+
bazel run //dotnet:format -- whitespace
2020

2121
section "Java"
2222
echo " google-java-format" >&2

0 commit comments

Comments
 (0)