<commit_before>// Copyright (c) 2020, the Dart project authors. Please see the AUTHORS file
// 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.

import 'package:analysis_server/src/services/correction/fix.dart';
import 'package:analysis_server/src/services/linter/lint_names.dart';
import 'package:analyzer_plugin/utilities/fixes/fixes.dart';
import 'package:test_reflective_loader/test_reflective_loader.dart';

import 'fix_processor.dart';

void main() {
  defineReflectiveSuite(() {
    defineReflectiveTests(ConvertToOnTypeTest);
  });
}

@reflectiveTest
class ConvertToOnTypeTest extends FixProcessorLintTest {
  @override
  FixKind get kind => DartFixKind.CONVERT_TO_ON_TYPE;

  @override
  String get lintCode => LintNames.avoid_types_as_parameter_names;

  Future<void> test_withOnType() async {
    await resolveTestCode('''
void f() {
  try {
  } on ArgumentError catch (Object) {
  }
}
''');
    await assertNoFix(
      errorFilter: lintNameFilter(
        LintNames.avoid_types_as_parameter_names,
      ),
    );
  }

  Future<void> test_withoutStackTrace() async {
    await resolveTestCode('''
void f() {
  try {
  } catch (ArgumentError) {
  }
}
''');
    await assertHasFix('''
void f() {
  try {
  } on ArgumentError {
  }
}
''');
  }

  Future<void> test_withStackTrace() async {
    await resolveTestCode('''
void f() {
  try {
  } catch (ArgumentError, st) {
    st;
  }
}
''');
    await assertHasFix('''
void f() {
  try {
  } on ArgumentError catch (_, st) {
    st;
  }
}
''');
  }
}
<commit_msg>Add a test case for convert-to-on-type<commit_after>// Copyright (c) 2020, the Dart project authors. Please see the AUTHORS file
// 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.

import 'package:analysis_server/src/services/correction/fix.dart';
import 'package:analysis_server/src/services/linter/lint_names.dart';
import 'package:analyzer_plugin/utilities/fixes/fixes.dart';
import 'package:test_reflective_loader/test_reflective_loader.dart';

import 'fix_processor.dart';

void main() {
  defineReflectiveSuite(() {
    defineReflectiveTests(ConvertToOnTypeTest);
  });
}

@reflectiveTest
class ConvertToOnTypeTest extends FixProcessorLintTest {
  @override
  FixKind get kind => DartFixKind.CONVERT_TO_ON_TYPE;

  @override
  String get lintCode => LintNames.avoid_types_as_parameter_names;

  Future<void> test_nameReferenced() async {
    await resolveTestCode('''
void f() {
  try {
  } catch (ArgumentError) {
    print(ArgumentError);
  }
}
''');
    await assertHasFix('''
void f() {
  try {
  } on ArgumentError {
    print(ArgumentError);
  }
}
''');
  }

  Future<void> test_withOnType() async {
    await resolveTestCode('''
void f() {
  try {
  } on ArgumentError catch (Object) {
  }
}
''');
    await assertNoFix(
      errorFilter: lintNameFilter(
        LintNames.avoid_types_as_parameter_names,
      ),
    );
  }

  Future<void> test_withoutStackTrace() async {
    await resolveTestCode('''
void f() {
  try {
  } catch (ArgumentError) {
  }
}
''');
    await assertHasFix('''
void f() {
  try {
  } on ArgumentError {
  }
}
''');
  }

  Future<void> test_withStackTrace() async {
    await resolveTestCode('''
void f() {
  try {
  } catch (ArgumentError, st) {
    st;
  }
}
''');
    await assertHasFix('''
void f() {
  try {
  } on ArgumentError catch (_, st) {
    st;
  }
}
''');
  }
}

{'fraction_non_alphanumeric': 0.13065755764304013, 'fraction_numerical': 0.002277255906632508, 'mean_word_length': 3.780952380952381, 'pattern_counts': {'":': 0, '<': 10, '<?xml version=': 0, '>': 14, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6723881', 'n_tokens_mistral': 1209, 'n_tokens_neox': 1196, 'n_words': 268}