From 4a6b541b0f474f90f89968fc9a44f87029f5b0ce Mon Sep 17 00:00:00 2001 From: Kevin Moore Date: Thu, 6 Feb 2025 12:20:07 -0800 Subject: [PATCH] Enable and fix unnecessary_ignore lint --- analysis_options.yaml | 1 + .../lib/src/type_helpers/json_converter_helper.dart | 1 - json_serializable/lib/src/utils.dart | 1 - .../test/supported_types/extra_map_test.dart | 1 - .../test/supported_types/type_test.bigint_test.dart | 5 ++--- .../test/supported_types/type_test.bool_test.dart | 5 ++--- json_serializable/test/supported_types/type_test.dart | 5 ++--- .../test/supported_types/type_test.datetime_test.dart | 5 ++--- .../test/supported_types/type_test.double_test.dart | 5 ++--- .../test/supported_types/type_test.duration_test.dart | 5 ++--- .../test/supported_types/type_test.enumtype_test.dart | 5 ++--- .../test/supported_types/type_test.int_test.dart | 5 ++--- .../test/supported_types/type_test.iterable_test.dart | 5 ++--- .../test/supported_types/type_test.list_test.dart | 5 ++--- .../test/supported_types/type_test.map_test.dart | 5 ++--- .../test/supported_types/type_test.num_test.dart | 5 ++--- .../test/supported_types/type_test.object_test.dart | 5 ++--- .../test/supported_types/type_test.set_test.dart | 5 ++--- .../test/supported_types/type_test.string_test.dart | 5 ++--- .../test/supported_types/type_test.uri_test.dart | 5 ++--- json_serializable/tool/test_type_data.dart | 8 ++++---- 21 files changed, 37 insertions(+), 55 deletions(-) diff --git a/analysis_options.yaml b/analysis_options.yaml index f45a2193b..5381bdab6 100644 --- a/analysis_options.yaml +++ b/analysis_options.yaml @@ -26,3 +26,4 @@ linter: - unnecessary_breaks - use_full_hex_values_for_flutter_colors - use_string_buffers + - unnecessary_ignore diff --git a/json_serializable/lib/src/type_helpers/json_converter_helper.dart b/json_serializable/lib/src/type_helpers/json_converter_helper.dart index 2722b4bc6..9958368af 100644 --- a/json_serializable/lib/src/type_helpers/json_converter_helper.dart +++ b/json_serializable/lib/src/type_helpers/json_converter_helper.dart @@ -214,7 +214,6 @@ _JsonConvertData? _typeConverterFrom( final annotationElement = match.elementAnnotation?.element; if (annotationElement is PropertyAccessorElement) { - // ignore: deprecated_member_use final enclosing = annotationElement.enclosingElement3; var accessString = annotationElement.name; diff --git a/json_serializable/lib/src/utils.dart b/json_serializable/lib/src/utils.dart index d2f5f3342..4d346b41e 100644 --- a/json_serializable/lib/src/utils.dart +++ b/json_serializable/lib/src/utils.dart @@ -131,7 +131,6 @@ ConstructorElement? _constructorByNameOrNull( ) { try { return constructorByName(classElement, name); - // ignore: avoid_catching_errors } on InvalidGenerationSourceError { return null; } diff --git a/json_serializable/test/supported_types/extra_map_test.dart b/json_serializable/test/supported_types/extra_map_test.dart index e4fc69c1d..c5ad878b2 100644 --- a/json_serializable/test/supported_types/extra_map_test.dart +++ b/json_serializable/test/supported_types/extra_map_test.dart @@ -2,7 +2,6 @@ // for details. All rights reserved. Use of this source code is governed by a // BSD-style license that can be found in the LICENSE file. -// ignore_for_file: prefer_const_declarations @TestOn('vm') library; diff --git a/json_serializable/test/supported_types/type_test.bigint_test.dart b/json_serializable/test/supported_types/type_test.bigint_test.dart index 1fa7140da..83cfa4031 100644 --- a/json_serializable/test/supported_types/type_test.bigint_test.dart +++ b/json_serializable/test/supported_types/type_test.bigint_test.dart @@ -2,7 +2,6 @@ // for details. All rights reserved. Use of this source code is governed by a // BSD-style license that can be found in the LICENSE file. -// ignore_for_file: prefer_const_declarations @TestOn('vm') library; @@ -87,8 +86,8 @@ void main() { }); // end nullable group } -final _defaultValue = '12345'; -final _altValue = '67890'; +const _defaultValue = '12345'; +const _altValue = '67890'; final _defaultInput = { 'value': _defaultValue, diff --git a/json_serializable/test/supported_types/type_test.bool_test.dart b/json_serializable/test/supported_types/type_test.bool_test.dart index 33d1e9bcc..dc28ab84c 100644 --- a/json_serializable/test/supported_types/type_test.bool_test.dart +++ b/json_serializable/test/supported_types/type_test.bool_test.dart @@ -2,7 +2,6 @@ // for details. All rights reserved. Use of this source code is governed by a // BSD-style license that can be found in the LICENSE file. -// ignore_for_file: prefer_const_declarations @TestOn('vm') library; @@ -87,8 +86,8 @@ void main() { }); // end nullable group } -final _defaultValue = true; -final _altValue = false; +const _defaultValue = true; +const _altValue = false; final _defaultInput = { 'value': _defaultValue, diff --git a/json_serializable/test/supported_types/type_test.dart b/json_serializable/test/supported_types/type_test.dart index 2e7c63a3a..7cc6fc069 100644 --- a/json_serializable/test/supported_types/type_test.dart +++ b/json_serializable/test/supported_types/type_test.dart @@ -2,7 +2,6 @@ // for details. All rights reserved. Use of this source code is governed by a // BSD-style license that can be found in the LICENSE file. -// ignore_for_file: prefer_const_declarations @TestOn('vm') library; @@ -53,8 +52,8 @@ void main() { }); // end non-nullable group } -final _defaultValue = 42; -final _altValue = 43; +const _defaultValue = 42; +const _altValue = 43; final _defaultInput = { 'value': _defaultValue, diff --git a/json_serializable/test/supported_types/type_test.datetime_test.dart b/json_serializable/test/supported_types/type_test.datetime_test.dart index 690cde74c..88d5f53db 100644 --- a/json_serializable/test/supported_types/type_test.datetime_test.dart +++ b/json_serializable/test/supported_types/type_test.datetime_test.dart @@ -2,7 +2,6 @@ // for details. All rights reserved. Use of this source code is governed by a // BSD-style license that can be found in the LICENSE file. -// ignore_for_file: prefer_const_declarations @TestOn('vm') library; @@ -87,8 +86,8 @@ void main() { }); // end nullable group } -final _defaultValue = '2020-01-01T00:00:00.000'; -final _altValue = '2018-01-01T00:00:00.000'; +const _defaultValue = '2020-01-01T00:00:00.000'; +const _altValue = '2018-01-01T00:00:00.000'; final _defaultInput = { 'value': _defaultValue, diff --git a/json_serializable/test/supported_types/type_test.double_test.dart b/json_serializable/test/supported_types/type_test.double_test.dart index 31c72aa00..5a55d9c93 100644 --- a/json_serializable/test/supported_types/type_test.double_test.dart +++ b/json_serializable/test/supported_types/type_test.double_test.dart @@ -2,7 +2,6 @@ // for details. All rights reserved. Use of this source code is governed by a // BSD-style license that can be found in the LICENSE file. -// ignore_for_file: prefer_const_declarations @TestOn('vm') library; @@ -87,8 +86,8 @@ void main() { }); // end nullable group } -final _defaultValue = 3.14; -final _altValue = 6.28; +const _defaultValue = 3.14; +const _altValue = 6.28; final _defaultInput = { 'value': _defaultValue, diff --git a/json_serializable/test/supported_types/type_test.duration_test.dart b/json_serializable/test/supported_types/type_test.duration_test.dart index a928fd914..4d5f71814 100644 --- a/json_serializable/test/supported_types/type_test.duration_test.dart +++ b/json_serializable/test/supported_types/type_test.duration_test.dart @@ -2,7 +2,6 @@ // for details. All rights reserved. Use of this source code is governed by a // BSD-style license that can be found in the LICENSE file. -// ignore_for_file: prefer_const_declarations @TestOn('vm') library; @@ -87,8 +86,8 @@ void main() { }); // end nullable group } -final _defaultValue = 1234; -final _altValue = 2345; +const _defaultValue = 1234; +const _altValue = 2345; final _defaultInput = { 'value': _defaultValue, diff --git a/json_serializable/test/supported_types/type_test.enumtype_test.dart b/json_serializable/test/supported_types/type_test.enumtype_test.dart index 3c2e8bc9a..363d1ab9a 100644 --- a/json_serializable/test/supported_types/type_test.enumtype_test.dart +++ b/json_serializable/test/supported_types/type_test.enumtype_test.dart @@ -2,7 +2,6 @@ // for details. All rights reserved. Use of this source code is governed by a // BSD-style license that can be found in the LICENSE file. -// ignore_for_file: prefer_const_declarations @TestOn('vm') library; @@ -87,8 +86,8 @@ void main() { }); // end nullable group } -final _defaultValue = 'alpha'; -final _altValue = 'beta'; +const _defaultValue = 'alpha'; +const _altValue = 'beta'; final _defaultInput = { 'value': _defaultValue, diff --git a/json_serializable/test/supported_types/type_test.int_test.dart b/json_serializable/test/supported_types/type_test.int_test.dart index b9f36ec4f..4e8c0cb27 100644 --- a/json_serializable/test/supported_types/type_test.int_test.dart +++ b/json_serializable/test/supported_types/type_test.int_test.dart @@ -2,7 +2,6 @@ // for details. All rights reserved. Use of this source code is governed by a // BSD-style license that can be found in the LICENSE file. -// ignore_for_file: prefer_const_declarations @TestOn('vm') library; @@ -87,8 +86,8 @@ void main() { }); // end nullable group } -final _defaultValue = 42; -final _altValue = 43; +const _defaultValue = 42; +const _altValue = 43; final _defaultInput = { 'value': _defaultValue, diff --git a/json_serializable/test/supported_types/type_test.iterable_test.dart b/json_serializable/test/supported_types/type_test.iterable_test.dart index b31313d97..1a2ae5960 100644 --- a/json_serializable/test/supported_types/type_test.iterable_test.dart +++ b/json_serializable/test/supported_types/type_test.iterable_test.dart @@ -2,7 +2,6 @@ // for details. All rights reserved. Use of this source code is governed by a // BSD-style license that can be found in the LICENSE file. -// ignore_for_file: prefer_const_declarations @TestOn('vm') library; @@ -87,8 +86,8 @@ void main() { }); // end nullable group } -final _defaultValue = [42, true, false, null]; -final _altValue = [43, false]; +const _defaultValue = [42, true, false, null]; +const _altValue = [43, false]; final _defaultInput = { 'value': _defaultValue, diff --git a/json_serializable/test/supported_types/type_test.list_test.dart b/json_serializable/test/supported_types/type_test.list_test.dart index 6791be995..36e673318 100644 --- a/json_serializable/test/supported_types/type_test.list_test.dart +++ b/json_serializable/test/supported_types/type_test.list_test.dart @@ -2,7 +2,6 @@ // for details. All rights reserved. Use of this source code is governed by a // BSD-style license that can be found in the LICENSE file. -// ignore_for_file: prefer_const_declarations @TestOn('vm') library; @@ -87,8 +86,8 @@ void main() { }); // end nullable group } -final _defaultValue = [42, true, false, null]; -final _altValue = [43, false]; +const _defaultValue = [42, true, false, null]; +const _altValue = [43, false]; final _defaultInput = { 'value': _defaultValue, diff --git a/json_serializable/test/supported_types/type_test.map_test.dart b/json_serializable/test/supported_types/type_test.map_test.dart index 2ccce34e6..925f233c2 100644 --- a/json_serializable/test/supported_types/type_test.map_test.dart +++ b/json_serializable/test/supported_types/type_test.map_test.dart @@ -2,7 +2,6 @@ // for details. All rights reserved. Use of this source code is governed by a // BSD-style license that can be found in the LICENSE file. -// ignore_for_file: prefer_const_declarations @TestOn('vm') library; @@ -87,8 +86,8 @@ void main() { }); // end nullable group } -final _defaultValue = {'a': 1}; -final _altValue = {'b': 2}; +const _defaultValue = {'a': 1}; +const _altValue = {'b': 2}; final _defaultInput = { 'value': _defaultValue, diff --git a/json_serializable/test/supported_types/type_test.num_test.dart b/json_serializable/test/supported_types/type_test.num_test.dart index 7cd62d61b..8489d5ff7 100644 --- a/json_serializable/test/supported_types/type_test.num_test.dart +++ b/json_serializable/test/supported_types/type_test.num_test.dart @@ -2,7 +2,6 @@ // for details. All rights reserved. Use of this source code is governed by a // BSD-style license that can be found in the LICENSE file. -// ignore_for_file: prefer_const_declarations @TestOn('vm') library; @@ -87,8 +86,8 @@ void main() { }); // end nullable group } -final _defaultValue = 88.6; -final _altValue = 29; +const _defaultValue = 88.6; +const _altValue = 29; final _defaultInput = { 'value': _defaultValue, diff --git a/json_serializable/test/supported_types/type_test.object_test.dart b/json_serializable/test/supported_types/type_test.object_test.dart index f6333fa7a..5cad9da25 100644 --- a/json_serializable/test/supported_types/type_test.object_test.dart +++ b/json_serializable/test/supported_types/type_test.object_test.dart @@ -2,7 +2,6 @@ // for details. All rights reserved. Use of this source code is governed by a // BSD-style license that can be found in the LICENSE file. -// ignore_for_file: prefer_const_declarations @TestOn('vm') library; @@ -87,8 +86,8 @@ void main() { }); // end nullable group } -final _defaultValue = 'o1'; -final _altValue = 'o2'; +const _defaultValue = 'o1'; +const _altValue = 'o2'; final _defaultInput = { 'value': _defaultValue, diff --git a/json_serializable/test/supported_types/type_test.set_test.dart b/json_serializable/test/supported_types/type_test.set_test.dart index 12f2521ee..b0af7da12 100644 --- a/json_serializable/test/supported_types/type_test.set_test.dart +++ b/json_serializable/test/supported_types/type_test.set_test.dart @@ -2,7 +2,6 @@ // for details. All rights reserved. Use of this source code is governed by a // BSD-style license that can be found in the LICENSE file. -// ignore_for_file: prefer_const_declarations @TestOn('vm') library; @@ -87,8 +86,8 @@ void main() { }); // end nullable group } -final _defaultValue = [42, true, false, null]; -final _altValue = [43, false]; +const _defaultValue = [42, true, false, null]; +const _altValue = [43, false]; final _defaultInput = { 'value': _defaultValue, diff --git a/json_serializable/test/supported_types/type_test.string_test.dart b/json_serializable/test/supported_types/type_test.string_test.dart index a868de260..2943b4424 100644 --- a/json_serializable/test/supported_types/type_test.string_test.dart +++ b/json_serializable/test/supported_types/type_test.string_test.dart @@ -2,7 +2,6 @@ // for details. All rights reserved. Use of this source code is governed by a // BSD-style license that can be found in the LICENSE file. -// ignore_for_file: prefer_const_declarations @TestOn('vm') library; @@ -87,8 +86,8 @@ void main() { }); // end nullable group } -final _defaultValue = 'a string'; -final _altValue = 'another string'; +const _defaultValue = 'a string'; +const _altValue = 'another string'; final _defaultInput = { 'value': _defaultValue, diff --git a/json_serializable/test/supported_types/type_test.uri_test.dart b/json_serializable/test/supported_types/type_test.uri_test.dart index c49a890fa..1d69a3c6f 100644 --- a/json_serializable/test/supported_types/type_test.uri_test.dart +++ b/json_serializable/test/supported_types/type_test.uri_test.dart @@ -2,7 +2,6 @@ // for details. All rights reserved. Use of this source code is governed by a // BSD-style license that can be found in the LICENSE file. -// ignore_for_file: prefer_const_declarations @TestOn('vm') library; @@ -87,8 +86,8 @@ void main() { }); // end nullable group } -final _defaultValue = 'https://example.com'; -final _altValue = 'https://dart.dev'; +const _defaultValue = 'https://example.com'; +const _altValue = 'https://dart.dev'; final _defaultInput = { 'value': _defaultValue, diff --git a/json_serializable/tool/test_type_data.dart b/json_serializable/tool/test_type_data.dart index 53ffb5b1c..6d785a448 100644 --- a/json_serializable/tool/test_type_data.dart +++ b/json_serializable/tool/test_type_data.dart @@ -242,12 +242,12 @@ class TestTypeData { yield Replacement( ''' -final _defaultValue = 42; -final _altValue = 43; +const _defaultValue = 42; +const _altValue = 43; ''', ''' -final _defaultValue = $jsonExpression; -final _altValue = $altJsonExpression; +const _defaultValue = $jsonExpression; +const _altValue = $altJsonExpression; ''', );