Compare commits

...

10 Commits

Author SHA1 Message Date
Lauro Moura 6d10db606f WIP - suppress PD issues 2019-12-03 18:21:43 -03:00
Lauro Moura 251703fcfe csharp: WIP - Cleanup unused parameters for structs
Ref T8414
2019-12-03 18:21:43 -03:00
Lauro Moura 0e6c6fab59 csharp: Suppress CA1801 for magic tags
These parameters are used only as a resolution method for extension
method ambiguity.

Ref T8414
2019-12-03 18:21:43 -03:00
Yeongjong Lee cf8b38dfd0 eolian_mono: remove unused EventArgs parameter of OnXXXEvent
Summary:
if a event doesn't have `EventArgs`, parameter `EventArgs e` of its OnXXXEvent
is naver used.

ref T8414

Test Plan: meson setup -Dbindings=mono,cxx -Dmono-beta=true

Reviewers: lauromoura

Subscribers: cedric, #reviewers, #committers

Tags: #efl

Maniphest Tasks: T8414

Differential Revision: https://phab.enlightenment.org/D10656
2019-12-03 18:21:43 -03:00
Lauro Moura 7ee645ac08 Enable CA1801 - Unused parameters 2019-12-03 18:21:43 -03:00
Lauro Moura 74374bb72a Start re-enabling some warnings after fixes 2019-12-03 18:21:18 -03:00
Lauro Moura edc0f14f2b csharp: Ignore all warnings individually
Make it easier to be working on each one
2019-12-03 18:21:18 -03:00
Lauro Moura 03583a6b00 csharp: Analyze test code too 2019-12-03 18:21:18 -03:00
Lauro Moura af9d57c68f Lets silence some rules 2019-12-03 18:21:18 -03:00
Lauro Moura 6452dca38f csharp: Add StyleCop support to dotnet build
Summary:
This patch builds on top of D9717 by adding support to run the StyleCop
rules (It imported the initial ruleset from P278 in
src/bindings/mono/ca.ruleset).

Depends on D9717

Reviewers: Jaehyun_Cho, YOhoho, woohyun

Subscribers: cedric, brunobelo, felipealmeida, #reviewers, segfaultxavi, #committers

Tags: #efl

Differential Revision: https://phab.enlightenment.org/D10433
2019-12-03 18:21:18 -03:00
7 changed files with 384 additions and 12 deletions

View File

@ -508,10 +508,19 @@ struct event_definition_generator
}
}
// Close summary
if (!as_generator(scope_tab << "/// </summary>\n").generate(sink, nullptr, context))
return false;
if (evt.type.is_engaged())
{
if (!as_generator(scope_tab << "/// <param name=\"e\">Event to raise.</param>\n"
).generate(sink, nullptr, context))
return false;
}
if (!as_generator(
scope_tab << "/// </summary>\n"
<< scope_tab << "/// <param name=\"e\">Event to raise.</param>\n"
<< scope_tab << (is_concrete ? "public" : "protected virtual") << " void On" << event_name << "(" << event_args_type << " e)\n"
scope_tab << (is_concrete ? "public" : "protected virtual") << " void On" << event_name << "(" << (!evt.type.is_engaged() ? "" : event_args_type + " e") << ")\n"
<< scope_tab << "{\n"
<< scope_tab << scope_tab << "var key = \"_" << upper_c_name << "\";\n"
<< scope_tab << scope_tab << "IntPtr desc = Efl.EventDescription.GetNative(" << library_name << ", key);\n"

View File

@ -124,6 +124,7 @@ struct native_function_definition_generator
if(!as_generator
(indent << "[SuppressMessage(\"Microsoft.Reliability\", \"CA2000:DisposeObjectsBeforeLosingScope\", Justification = \"The instantiated objects can be stored in the called Managed API method.\")]\n"
<< indent << "[SuppressMessage(\"Microsoft.Usage\", \"CA1801:ReviweUnusedParameters\", Justification = \"The parameter \\\"pd\\\" is a requirement from the C API wrapped by this method.\")]\n"
<< indent << "private static "
<< eolian_mono::marshall_type(true) << " "
<< string
@ -284,7 +285,8 @@ struct property_extension_method_definition_generator
if (property.setter.is_engaged())
{
attributes::type_def prop_type = property.setter->parameters[0].type;
if (!as_generator(scope_tab << "public static Efl.BindableProperty<" << type(true) << "> " << managed_name << "<T>(this Efl.Ui.ItemFactory<T> fac, Efl.Csharp.ExtensionTag<"
if (!as_generator(scope_tab << "[SuppressMessage(\"Microsoft.Usage\", \"CA1801:ReviweUnusedParameters\", Justification = \"The parameter is used only for extension method overload resolution.\")]\n"
<< scope_tab << "public static Efl.BindableProperty<" << type(true) << "> " << managed_name << "<T>(this Efl.Ui.ItemFactory<T> fac, Efl.Csharp.ExtensionTag<"
<< name_helpers::klass_full_concrete_or_interface_name(cls)
<< ", T>magic = null) where T : " << name_helpers::klass_full_concrete_or_interface_name(cls) << " {\n"
<< scope_tab << scope_tab << "return new Efl.BindableProperty<" << type(true) << ">(\"" << property.name << "\", fac);\n"
@ -301,7 +303,8 @@ struct property_extension_method_definition_generator
if (property.setter.is_engaged())
{
attributes::type_def prop_type = property.setter->parameters[0].type;
if (!as_generator(scope_tab << "public static Efl.BindableProperty<" << type(true) << "> " << managed_name << "<T>(this Efl.BindablePart<T> part, Efl.Csharp.ExtensionTag<"
if (!as_generator(scope_tab << "[SuppressMessage(\"Microsoft.Usage\", \"CA1801:ReviweUnusedParameters\", Justification = \"The parameter is used only for extension method overload resolution.\")]\n"
<< scope_tab << "public static Efl.BindableProperty<" << type(true) << "> " << managed_name << "<T>(this Efl.BindablePart<T> part, Efl.Csharp.ExtensionTag<"
<< name_helpers::klass_full_concrete_or_interface_name(cls)
<< ", T>magic = null) where T : " << name_helpers::klass_full_concrete_or_interface_name(cls) << " {\n"
<< scope_tab << scope_tab << "return new Efl.BindableProperty<" << type(true) << ">(part.PartName, \"" << property.name << "\", part.Binder);\n"

View File

@ -361,10 +361,20 @@ struct struct_internal_definition_generator
).generate(sink, std::make_tuple(internal_name, external_name, internal_name), context))
return false;
for (auto const& field : struct_.fields)
if (struct_.fields.size() >= 1)
{
if (!to_internal_field_convert.generate(sink, field, context))
return false;
for (auto const& field : struct_.fields)
{
if (!to_internal_field_convert.generate(sink, field, context))
return false;
}
}
else
{
if (!as_generator(
indent << scope_tab << scope_tab << "_internal_struct.field = _external_struct.field;\n"
).generate(sink, attributes::unused, context))
return false;
}
if (!as_generator(indent << scope_tab << scope_tab << "return _internal_struct;\n"
@ -380,10 +390,20 @@ struct struct_internal_definition_generator
).generate(sink, std::make_tuple(external_name, internal_name, external_name), context))
return false;
for (auto const& field : struct_.fields)
if (struct_.fields.size() != 0)
{
if (!to_external_field_convert.generate(sink, field, context))
return false;
for (auto const& field : struct_.fields)
{
if (!to_external_field_convert.generate(sink, field, context))
return false;
}
}
else
{
if (!as_generator(
indent << scope_tab << scope_tab << "_external_struct.field = _internal_struct.field;\n"
).generate(sink, attributes::unused, context))
return false;
}
if (!as_generator(indent << scope_tab << scope_tab << "return _external_struct;\n"

View File

@ -0,0 +1,328 @@
<?xml version="1.0" encoding="utf-8"?>
<RuleSet Name="CustomRulset" Description="Custom Rulset" ToolsVersion="14.0">
<Rules AnalyzerId="Microsoft.Analyzers.ManagedCodeAnalysis" RuleNamespace="Microsoft.Rules.Managed">
<!-- Do not declare static members on Generic Types -->
<Rule Id="CA1000" Action="None"/>
<!-- Consider making Raise an event -->
<Rule Id="CA1030" Action="None"/>
<!-- Catch generic exception -->
<Rule Id="CA1031" Action="None"/>
<!-- Add extra exception constructors -->
<Rule Id="CA1032" Action="Warning"/>
<!-- Do not nest NativeTypes -->
<Rule Id="CA1034" Action="None"/>
<!-- IComparable must implement other comparison operators -->
<Rule Id="CA1036" Action="None"/>
<!-- Avoid empty interface -->
<Rule Id="CA1040" Action="Warning"/>
<!-- Consider making property with getter -->
<Rule Id="CA1044" Action="None"/>
<!-- Visible instance fields -->
<Rule Id="CA1051" Action="None"/>
<!-- Static holder can be static -->
<Rule Id="CA1052" Action="None"/>
<!-- Using parameters before checking for null -->
<Rule Id="CA1062" Action="None"/>
<!-- Remove IDisposable as Object already has it -->
<Rule Id="CA1063" Action="Warning"/>
<!-- Exceptions must be public -->
<Rule Id="CA1064" Action="Warning"/>
<!-- Do not raise exception in unexpected locations -->
<Rule Id="CA1065" Action="None"/>
<!-- String localization -->
<Rule Id="CA1303" Action="None"/>
<!-- Specify IFormatProvider -->
<Rule Id="CA1305" Action="None"/>
<!-- Specify Stringcomparison -->
<Rule Id="CA1307" Action="Warning"/>
<!-- PInvoke should not be visible -->
<Rule Id="CA1401" Action="Warning"/>
<!-- Use nameof -->
<Rule Id="CA1507" Action="None"/>
<!-- Parameter underscore -->
<Rule Id="CA1707" Action="None"/>
<!-- Attribute classes must have the Attribute Suffix -->
<Rule Id="CA1710" Action="None"/>
<!-- Replace generic parameter with T -->
<Rule Id="CA1715" Action="None"/>
<!-- Parameter End conflicts with VB -->
<Rule Id="CA1716" Action="None"/>
<!-- Enum field must be plural -->
<Rule Id="CA1717" Action="Warning"/>
<!-- Variable has type name -->
<Rule Id="CA1720" Action="None"/>
<!-- Property with same name as getter -->
<Rule Id="CA1721" Action="None"/>
<!-- Type name must not match namespace -->
<Rule Id="CA1724" Action="None"/>
<!-- Unused parameter. Lots of warnings regarding Dispose(disposing) -->
<Rule Id="CA1801" Action="Warning"/>
<!-- Do not ignore function result -->
<Rule Id="CA1806" Action="None"/>
<!-- Remove static constructors -->
<Rule Id="CA1810" Action="None"/>
<!-- Realized classes are never instantiated -->
<Rule Id="CA1812" Action="None"/>
<!-- Override equal and operator equal on Value Types-->
<Rule Id="CA1815" Action="Warning"/>
<!-- Dispose must call SuppressFinalizers -->
<Rule Id="CA1816" Action="Warning"/>
<!-- Member can be static -->
<Rule Id="CA1822" Action="None"/>
<!-- Consider zero length array allocation -->
<Rule Id="CA1825" Action="Warning"/>
<!-- Use Count instead of Count() -->
<Rule Id="CA1829" Action="Warning"/>
<!-- Call dispose before going out of scope -->
<Rule Id="CA2000" Action="None"/>
<!-- Call ConfigureWait-->
<Rule Id="CA2007" Action="Warning"/>
<!-- PInvoke should specify string marshalling -->
<Rule Id="CA2101" Action="None"/>
<!-- Rethrow loses stack info -->
<Rule Id="CA2200" Action="Warning"/>
<!-- Declare static fields when they are declared and remove static constructor -->
<Rule Id="CA2207" Action="Warning"/>
<!-- Instantiate exception params correctly -->
<Rule Id="CA2208" Action="Warning"/>
<!-- Dot not call overrideable methods in constructors -->
<Rule Id="CA2214" Action="None"/>
<!-- Replace implicit operator -->
<Rule Id="CA2225" Action="Warning"/>
</Rules>
<Rules AnalyzerId="StyleCop.Analyzers" RuleNamespace="StyleCop.Analyzers">
<!-- Ignore docs -->
<Rule Id="SA0001" Action="None"/>
<!-- 10** Spacing rules -->
<Rule Id="SA1000" Action="None"/>
<Rule Id="SA1001" Action="None"/>
<Rule Id="SA1002" Action="None"/>
<Rule Id="SA1003" Action="None"/>
<!-- Documentation must start with single space -->
<Rule Id="SA1004" Action="None"/>
<Rule Id="SA1005" Action="None"/>
<Rule Id="SA1006" Action="None"/>
<Rule Id="SA1007" Action="None"/>
<Rule Id="SA1008" Action="None"/>
<Rule Id="SA1009" Action="None"/>
<Rule Id="SA1010" Action="None"/>
<Rule Id="SA1011" Action="None"/>
<Rule Id="SA1012" Action="None"/>
<Rule Id="SA1013" Action="None"/>
<Rule Id="SA1014" Action="None"/>
<Rule Id="SA1015" Action="None"/>
<Rule Id="SA1016" Action="None"/>
<Rule Id="SA1017" Action="None"/>
<Rule Id="SA1018" Action="None"/>
<Rule Id="SA1019" Action="None"/>
<Rule Id="SA1020" Action="None"/>
<Rule Id="SA1021" Action="None"/>
<Rule Id="SA1022" Action="None"/>
<Rule Id="SA1023" Action="None"/>
<Rule Id="SA1024" Action="None"/>
<Rule Id="SA1025" Action="None"/>
<Rule Id="SA1026" Action="None"/>
<Rule Id="SA1027" Action="None"/>
<Rule Id="SA1028" Action="None"/>
<!-- Readability -->
<Rule Id="SA1100" Action="None"/>
<Rule Id="SA1101" Action="None"/>
<Rule Id="SA1102" Action="None"/>
<Rule Id="SA1103" Action="None"/>
<Rule Id="SA1104" Action="None"/>
<Rule Id="SA1105" Action="None"/>
<Rule Id="SA1106" Action="None"/>
<Rule Id="SA1107" Action="None"/>
<Rule Id="SA1108" Action="None"/>
<Rule Id="SA1109" Action="None"/>
<Rule Id="SA1110" Action="None"/>
<Rule Id="SA1111" Action="None"/>
<Rule Id="SA1112" Action="None"/>
<Rule Id="SA1113" Action="None"/>
<Rule Id="SA1114" Action="None"/>
<Rule Id="SA1115" Action="None"/>
<Rule Id="SA1116" Action="None"/>
<Rule Id="SA1117" Action="None"/>
<Rule Id="SA1118" Action="None"/>
<Rule Id="SA1119" Action="None"/>
<Rule Id="SA1120" Action="None"/>
<Rule Id="SA1121" Action="None"/>
<Rule Id="SA1122" Action="None"/>
<Rule Id="SA1123" Action="None"/>
<Rule Id="SA1124" Action="None"/>
<Rule Id="SA1125" Action="None"/>
<Rule Id="SA1126" Action="None"/>
<Rule Id="SA1127" Action="None"/>
<Rule Id="SA1128" Action="None"/>
<Rule Id="SA1129" Action="None"/>
<Rule Id="SA1130" Action="None"/>
<Rule Id="SA1131" Action="None"/>
<Rule Id="SA1132" Action="None"/>
<Rule Id="SA1133" Action="None"/>
<Rule Id="SA1134" Action="None"/>
<Rule Id="SA1135" Action="None"/>
<Rule Id="SA1136" Action="None"/>
<Rule Id="SA1137" Action="None"/>
<Rule Id="SA1138" Action="None"/>
<Rule Id="SA1139" Action="None"/>
<!-- 12** Ordering -->
<!-- FIXME Check if this somehow affects docfx output -->
<Rule Id="SA1200" Action="None"/>
<Rule Id="SA1201" Action="None"/>
<Rule Id="SA1202" Action="None"/>
<Rule Id="SA1203" Action="None"/>
<Rule Id="SA1204" Action="None"/>
<Rule Id="SA1205" Action="None"/>
<Rule Id="SA1206" Action="None"/>
<Rule Id="SA1207" Action="None"/>
<Rule Id="SA1208" Action="None"/>
<Rule Id="SA1209" Action="None"/>
<Rule Id="SA1210" Action="None"/>
<Rule Id="SA1211" Action="None"/>
<Rule Id="SA1212" Action="None"/>
<Rule Id="SA1213" Action="None"/>
<Rule Id="SA1214" Action="None"/>
<Rule Id="SA1215" Action="None"/>
<Rule Id="SA1216" Action="None"/>
<Rule Id="SA1217" Action="None"/>
<!-- 13** Naming Rules -->
<!-- Element start with upper case -->
<Rule Id="SA1300" Action="None"/>
<Rule Id="SA1301" Action="None"/>
<!-- Interface start with I -->
<Rule Id="SA1302" Action="None"/>
<!-- Upper/lower score rules -->
<Rule Id="SA1303" Action="None"/>
<Rule Id="SA1304" Action="None"/>
<Rule Id="SA1305" Action="None"/>
<Rule Id="SA1306" Action="None"/>
<Rule Id="SA1307" Action="None"/>
<!-- Variable field prefixes -->
<Rule Id="SA1308" Action="None"/>
<Rule Id="SA1309" Action="None"/>
<Rule Id="SA1310" Action="None"/>
<Rule Id="SA1311" Action="None"/>
<Rule Id="SA1312" Action="None"/> <!-- Variables, not part of public API -->
<Rule Id="SA1313" Action="None"/>
<Rule Id="SA1314" Action="None"/>
<!-- 14** Maintainability -->
<!-- Access modifier -->
<Rule Id="SA1400" Action="None"/>
<!-- Field must be private -->
<Rule Id="SA1401" Action="None"/>
<!-- File Must contain single class or namespace -->
<Rule Id="SA1402" Action="None"/>
<Rule Id="SA1403" Action="None"/>
<!-- CodeAnalysis suppress does not have justification -->
<Rule Id="SA1404" Action="None"/>
<!-- Debug.Assert/Fail must provide a message -->
<Rule Id="SA1405" Action="None"/>
<Rule Id="SA1406" Action="None"/>
<!-- Arithmetic/Conditional expression must declare precedence -->
<Rule Id="SA1407" Action="None"/>
<Rule Id="SA1408" Action="None"/>
<!-- Remove unecessary code -->
<Rule Id="SA1409" Action="None"/>
<!-- Delegate/Attribute parentheses -->
<Rule Id="SA1410" Action="None"/>
<Rule Id="SA1411" Action="None"/>
<!-- Utf8 file -->
<Rule Id="SA1412" Action="None"/>
<!-- Trailing commas multiline initializer -->
<Rule Id="SA1413" Action="None"/>
<!-- 15** Layout Rules -->
<Rule Id="SA1500" Action="None"/>
<Rule Id="SA1501" Action="None"/>
<Rule Id="SA1502" Action="None"/>
<Rule Id="SA1503" Action="None"/>
<Rule Id="SA1504" Action="None"/>
<Rule Id="SA1505" Action="None"/>
<Rule Id="SA1506" Action="None"/>
<Rule Id="SA1507" Action="None"/>
<Rule Id="SA1508" Action="None"/>
<Rule Id="SA1509" Action="None"/>
<Rule Id="SA1510" Action="None"/>
<Rule Id="SA1511" Action="None"/>
<Rule Id="SA1512" Action="None"/>
<Rule Id="SA1513" Action="None"/>
<Rule Id="SA1514" Action="None"/>
<Rule Id="SA1515" Action="None"/>
<Rule Id="SA1516" Action="None"/>
<Rule Id="SA1517" Action="None"/>
<Rule Id="SA1518" Action="None"/>
<Rule Id="SA1519" Action="None"/>
<Rule Id="SA1520" Action="None"/>
<!-- 16** Documentation rules -->
<!-- Things must be documented -->
<Rule Id="SA1600" Action="None"/>
<Rule Id="SA1601" Action="None"/>
<Rule Id="SA1602" Action="None"/>
<!-- Valid xml in docs -->
<Rule Id="SA1603" Action="None"/>
<Rule Id="SA1604" Action="None"/>
<Rule Id="SA1605" Action="None"/>
<Rule Id="SA1606" Action="None"/>
<Rule Id="SA1607" Action="None"/>
<Rule Id="SA1608" Action="None"/>
<Rule Id="SA1609" Action="None"/>
<Rule Id="SA1610" Action="None"/>
<Rule Id="SA1611" Action="None"/>
<Rule Id="SA1612" Action="None"/>
<Rule Id="SA1613" Action="None"/>
<Rule Id="SA1614" Action="None"/>
<Rule Id="SA1615" Action="None"/>
<Rule Id="SA1616" Action="None"/>
<Rule Id="SA1617" Action="None"/>
<Rule Id="SA1618" Action="None"/>
<Rule Id="SA1619" Action="None"/>
<Rule Id="SA1620" Action="None"/>
<Rule Id="SA1621" Action="None"/>
<Rule Id="SA1622" Action="None"/>
<Rule Id="SA1623" Action="None"/>
<Rule Id="SA1624" Action="None"/>
<Rule Id="SA1625" Action="None"/> <!-- Copy paste doc. May be problematic with generated code -->
<Rule Id="SA1626" Action="None"/>
<Rule Id="SA1627" Action="None"/>
<Rule Id="SA1628" Action="None"/>
<Rule Id="SA1629" Action="None"/>
<Rule Id="SA1630" Action="None"/>
<Rule Id="SA1631" Action="None"/>
<Rule Id="SA1632" Action="None"/>
<!-- File headers -->
<Rule Id="SA1633" Action="None"/>
<Rule Id="SA1634" Action="None"/>
<Rule Id="SA1635" Action="None"/>
<Rule Id="SA1636" Action="None"/>
<Rule Id="SA1637" Action="None"/>
<Rule Id="SA1638" Action="None"/>
<Rule Id="SA1639" Action="None"/>
<Rule Id="SA1640" Action="None"/>
<Rule Id="SA1641" Action="None"/>
<!-- Constructor/Destructor -->
<Rule Id="SA1642" Action="None"/>
<Rule Id="SA1643" Action="None"/>
<!-- File header -->
<Rule Id="SA1644" Action="None"/>
<!-- Miscellaneous doc -->
<Rule Id="SA1645" Action="None"/>
<Rule Id="SA1646" Action="None"/>
<Rule Id="SA1647" Action="None"/>
<Rule Id="SA1648" Action="None"/>
<!-- Filename must match file type -->
<Rule Id="SA1649" Action="None"/>
<!-- Spelling -->
<Rule Id="SA1650" Action="None"/>
<!-- Placeholder -->
<Rule Id="SA1651" Action="None"/>
</Rules>
</RuleSet>

View File

@ -41,4 +41,13 @@
<Compile Include="./*.cs" />
</ItemGroup>
<!-- Code style configuration -->
<ItemGroup>
<PackageReference Include="Microsoft.CodeAnalysis.FxCopAnalyzers" Version="2.9.6" />
<PackageReference Include="StyleCop.Analyzers" Version="1.1.118" />
</ItemGroup>
<PropertyGroup>
<CodeAnalysisRuleSet>@BINDING_SRC@/ca.ruleset</CodeAnalysisRuleSet>
</PropertyGroup>
</Project>

View File

@ -173,7 +173,7 @@ if (get_option('dotnet'))
configuration: lib_csproj_conf_data)
efl_mono = custom_target('efl_mono',
input: mono_generator_target + mono_files + [efl_src] + [lib_csproj],
input: mono_generator_target + mono_files + [efl_src] + [lib_csproj] + ['ca.ruleset'],
output: 'efl_sharp.dll',
build_by_default: true,
command: [dotnet,

View File

@ -19,6 +19,9 @@
<ItemGroup>
<ProjectReference Include="../../bindings/mono/efl_sharp.csproj" />
</ItemGroup>
<PropertyGroup>
<CodeAnalysisRuleSet>@BINDING_TEST_SRC@/../../bindings/mono/ca.ruleset</CodeAnalysisRuleSet>
</PropertyGroup>
<ItemGroup>
<Compile Include="@BINDING_TEST_SRC@/*.cs" />