From fdc9f6e0ef7474e9e070d6f6032b039f18dac08f Mon Sep 17 00:00:00 2001 From: Evgeniy Okolnov Date: Fri, 15 Sep 2023 00:16:02 +0300 Subject: [PATCH] [ArkTS Linter] #13550: Fix check for dynamic type when context type is union type. Change-Id: I91a04a61ed72d3c1c4e569d47d100c809ea41ac5 Signed-off-by: Evgeniy Okolnov --- linter-4.2/.gitignore | 1 + linter-4.2/package.json | 5 +- .../{test => scripts}/update-test-results.bat | 0 .../{test => scripts}/update-test-results.mjs | 51 ++++++----- .../{test => scripts}/update-test-results.sh | 0 linter-4.2/src/Problems.ts | 5 +- linter-4.2/src/TestRunner.ts | 59 ++++++------ linter-4.2/src/Utils.ts | 11 +-- linter-4.2/test/dynamic_lib.d.ts | 21 +++++ linter-4.2/test/dynamic_object_literals.ts | 21 ++++- linter-4.2/test_rules/rule1.ts | 14 +++ linter-4.2/test_rules/rule1.ts.autofix.json | 82 +++++++++++++++++ linter-4.2/test_rules/rule1.ts.relax.json | 18 ++++ linter-4.2/test_rules/rule1.ts.strict.json | 60 +++++++++++++ linter-4.2/test_rules/rule102.ts | 76 ++++++++++++++++ linter-4.2/test_rules/rule102.ts.autofix.json | 90 +++++++++++++++++++ linter-4.2/test_rules/rule102.ts.relax.json | 81 +++++++++++++++++ linter-4.2/test_rules/rule102.ts.strict.json | 81 +++++++++++++++++ linter-4.2/test_rules/rule103.ts | 13 +++ linter-4.2/test_rules/rule103.ts.autofix.json | 74 +++++++++++++++ linter-4.2/test_rules/rule103.ts.relax.json | 32 +++++++ linter-4.2/test_rules/rule103.ts.strict.json | 67 ++++++++++++++ linter-4.2/test_rules/rule104.ts | 7 ++ linter-4.2/test_rules/rule104.ts.autofix.json | 12 +++ linter-4.2/test_rules/rule104.ts.relax.json | 11 +++ linter-4.2/test_rules/rule104.ts.strict.json | 11 +++ linter-4.2/test_rules/rule105.ts | 15 ++++ linter-4.2/test_rules/rule105.ts.autofix.json | 28 ++++++ linter-4.2/test_rules/rule105.ts.relax.json | 25 ++++++ linter-4.2/test_rules/rule105.ts.strict.json | 25 ++++++ linter-4.2/test_rules/rule106.ts | 14 +++ linter-4.2/test_rules/rule106.ts.autofix.json | 34 +++++++ linter-4.2/test_rules/rule106.ts.relax.json | 32 +++++++ linter-4.2/test_rules/rule106.ts.strict.json | 32 +++++++ linter-4.2/test_rules/rule109.ts | 12 +++ linter-4.2/test_rules/rule109.ts.autofix.json | 20 +++++ linter-4.2/test_rules/rule109.ts.relax.json | 18 ++++ linter-4.2/test_rules/rule109.ts.strict.json | 18 ++++ linter-4.2/test_rules/rule111.ts | 14 +++ linter-4.2/test_rules/rule111.ts.autofix.json | 28 ++++++ linter-4.2/test_rules/rule111.ts.relax.json | 25 ++++++ linter-4.2/test_rules/rule111.ts.strict.json | 25 ++++++ linter-4.2/test_rules/rule113.ts | 11 +++ linter-4.2/test_rules/rule113.ts.autofix.json | 28 ++++++ linter-4.2/test_rules/rule113.ts.relax.json | 25 ++++++ linter-4.2/test_rules/rule113.ts.strict.json | 25 ++++++ linter-4.2/test_rules/rule114.ts | 6 ++ linter-4.2/test_rules/rule114.ts.autofix.json | 12 +++ linter-4.2/test_rules/rule114.ts.relax.json | 11 +++ linter-4.2/test_rules/rule114.ts.strict.json | 11 +++ linter-4.2/test_rules/rule116.ts | 4 + linter-4.2/test_rules/rule116.ts.autofix.json | 12 +++ linter-4.2/test_rules/rule116.ts.relax.json | 11 +++ linter-4.2/test_rules/rule116.ts.strict.json | 11 +++ linter-4.2/test_rules/rule118.ts | 5 ++ linter-4.2/test_rules/rule118.ts.autofix.json | 19 ++++ linter-4.2/test_rules/rule118.ts.relax.json | 3 + linter-4.2/test_rules/rule118.ts.strict.json | 11 +++ linter-4.2/test_rules/rule119.ts | 9 ++ linter-4.2/test_rules/rule119.ts.autofix.json | 19 ++++ linter-4.2/test_rules/rule119.ts.relax.json | 17 ++++ linter-4.2/test_rules/rule119.ts.strict.json | 17 ++++ linter-4.2/test_rules/rule120.ts | 1 + linter-4.2/test_rules/rule120.ts.autofix.json | 19 ++++ linter-4.2/test_rules/rule120.ts.relax.json | 3 + linter-4.2/test_rules/rule120.ts.strict.json | 11 +++ linter-4.2/test_rules/rule121.ts | 1 + linter-4.2/test_rules/rule121.ts.autofix.json | 12 +++ linter-4.2/test_rules/rule121.ts.relax.json | 11 +++ linter-4.2/test_rules/rule121.ts.strict.json | 11 +++ linter-4.2/test_rules/rule125.ts | 13 +++ linter-4.2/test_rules/rule125.ts.autofix.json | 19 ++++ linter-4.2/test_rules/rule125.ts.relax.json | 17 ++++ linter-4.2/test_rules/rule125.ts.strict.json | 17 ++++ linter-4.2/test_rules/rule126.ts | 12 +++ linter-4.2/test_rules/rule126.ts.autofix.json | 28 ++++++ linter-4.2/test_rules/rule126.ts.relax.json | 25 ++++++ linter-4.2/test_rules/rule126.ts.strict.json | 25 ++++++ linter-4.2/test_rules/rule127.ts | 12 +++ linter-4.2/test_rules/rule127.ts.autofix.json | 19 ++++ linter-4.2/test_rules/rule127.ts.relax.json | 3 + linter-4.2/test_rules/rule127.ts.strict.json | 11 +++ linter-4.2/test_rules/rule128.ts | 3 + linter-4.2/test_rules/rule128.ts.autofix.json | 12 +++ linter-4.2/test_rules/rule128.ts.relax.json | 11 +++ linter-4.2/test_rules/rule128.ts.strict.json | 11 +++ linter-4.2/test_rules/rule129.ts | 8 ++ linter-4.2/test_rules/rule129.ts.autofix.json | 43 +++++++++ linter-4.2/test_rules/rule129.ts.relax.json | 38 ++++++++ linter-4.2/test_rules/rule129.ts.strict.json | 38 ++++++++ linter-4.2/test_rules/rule13.ts | 8 ++ linter-4.2/test_rules/rule13.ts.autofix.json | 36 ++++++++ linter-4.2/test_rules/rule13.ts.relax.json | 11 +++ linter-4.2/test_rules/rule13.ts.strict.json | 32 +++++++ linter-4.2/test_rules/rule130.ts | 6 ++ linter-4.2/test_rules/rule130.ts.autofix.json | 20 +++++ linter-4.2/test_rules/rule130.ts.relax.json | 18 ++++ linter-4.2/test_rules/rule130.ts.strict.json | 18 ++++ linter-4.2/test_rules/rule132.ts | 9 ++ linter-4.2/test_rules/rule132.ts.autofix.json | 28 ++++++ linter-4.2/test_rules/rule132.ts.relax.json | 25 ++++++ linter-4.2/test_rules/rule132.ts.strict.json | 25 ++++++ linter-4.2/test_rules/rule133.ts | 1 + linter-4.2/test_rules/rule133.ts.autofix.json | 12 +++ linter-4.2/test_rules/rule133.ts.relax.json | 11 +++ linter-4.2/test_rules/rule133.ts.strict.json | 11 +++ linter-4.2/test_rules/rule134.ts | 9 ++ linter-4.2/test_rules/rule134.ts.autofix.json | 12 +++ linter-4.2/test_rules/rule134.ts.relax.json | 11 +++ linter-4.2/test_rules/rule134.ts.strict.json | 11 +++ linter-4.2/test_rules/rule135.ts | 8 ++ linter-4.2/test_rules/rule135.ts.autofix.json | 43 +++++++++ linter-4.2/test_rules/rule135.ts.relax.json | 11 +++ linter-4.2/test_rules/rule135.ts.strict.json | 32 +++++++ linter-4.2/test_rules/rule136.ts | 13 +++ linter-4.2/test_rules/rule136.ts.autofix.json | 68 ++++++++++++++ linter-4.2/test_rules/rule136.ts.relax.json | 39 ++++++++ linter-4.2/test_rules/rule136.ts.strict.json | 60 +++++++++++++ linter-4.2/test_rules/rule137.ts | 5 ++ linter-4.2/test_rules/rule137.ts.autofix.json | 20 +++++ linter-4.2/test_rules/rule137.ts.relax.json | 11 +++ linter-4.2/test_rules/rule137.ts.strict.json | 18 ++++ linter-4.2/test_rules/rule138.ts | 22 +++++ linter-4.2/test_rules/rule138.ts.autofix.json | 36 ++++++++ linter-4.2/test_rules/rule138.ts.relax.json | 32 +++++++ linter-4.2/test_rules/rule138.ts.strict.json | 32 +++++++ linter-4.2/test_rules/rule139.ts | 23 +++++ linter-4.2/test_rules/rule139.ts.autofix.json | 57 ++++++++++++ linter-4.2/test_rules/rule139.ts.relax.json | 39 ++++++++ linter-4.2/test_rules/rule139.ts.strict.json | 46 ++++++++++ linter-4.2/test_rules/rule14.ts | 8 ++ linter-4.2/test_rules/rule14.ts.autofix.json | 20 +++++ linter-4.2/test_rules/rule14.ts.relax.json | 18 ++++ linter-4.2/test_rules/rule14.ts.strict.json | 18 ++++ linter-4.2/test_rules/rule140.ts | 23 +++++ linter-4.2/test_rules/rule140.ts.autofix.json | 57 ++++++++++++ linter-4.2/test_rules/rule140.ts.relax.json | 39 ++++++++ linter-4.2/test_rules/rule140.ts.strict.json | 46 ++++++++++ linter-4.2/test_rules/rule141.ts | 4 + linter-4.2/test_rules/rule141.ts.autofix.json | 19 ++++ linter-4.2/test_rules/rule141.ts.relax.json | 3 + linter-4.2/test_rules/rule141.ts.strict.json | 11 +++ linter-4.2/test_rules/rule142.ts | 8 ++ linter-4.2/test_rules/rule142.ts.autofix.json | 36 ++++++++ linter-4.2/test_rules/rule142.ts.relax.json | 32 +++++++ linter-4.2/test_rules/rule142.ts.strict.json | 32 +++++++ linter-4.2/test_rules/rule145.ts | 16 ++++ linter-4.2/test_rules/rule145.ts.autofix.json | 36 ++++++++ linter-4.2/test_rules/rule145.ts.relax.json | 32 +++++++ linter-4.2/test_rules/rule145.ts.strict.json | 32 +++++++ linter-4.2/test_rules/rule146.ts | 9 ++ linter-4.2/test_rules/rule146.ts.autofix.json | 20 +++++ linter-4.2/test_rules/rule146.ts.relax.json | 18 ++++ linter-4.2/test_rules/rule146.ts.strict.json | 18 ++++ linter-4.2/test_rules/rule147.ts | 7 ++ linter-4.2/test_rules/rule147.ts.autofix.json | 34 +++++++ linter-4.2/test_rules/rule147.ts.relax.json | 10 +++ linter-4.2/test_rules/rule147.ts.strict.json | 32 +++++++ linter-4.2/test_rules/rule148.ts | 7 ++ linter-4.2/test_rules/rule148.ts.autofix.json | 27 ++++++ linter-4.2/test_rules/rule148.ts.relax.json | 24 +++++ linter-4.2/test_rules/rule148.ts.strict.json | 24 +++++ linter-4.2/test_rules/rule15.ts | 21 +++++ linter-4.2/test_rules/rule15.ts.autofix.json | 20 +++++ linter-4.2/test_rules/rule15.ts.relax.json | 18 ++++ linter-4.2/test_rules/rule15.ts.strict.json | 18 ++++ linter-4.2/test_rules/rule17.ts | 17 ++++ linter-4.2/test_rules/rule17.ts.autofix.json | 34 +++++++ linter-4.2/test_rules/rule17.ts.relax.json | 11 +++ linter-4.2/test_rules/rule17.ts.strict.json | 18 ++++ linter-4.2/test_rules/rule19.ts | 13 +++ linter-4.2/test_rules/rule19.ts.autofix.json | 12 +++ linter-4.2/test_rules/rule19.ts.relax.json | 11 +++ linter-4.2/test_rules/rule19.ts.strict.json | 11 +++ linter-4.2/test_rules/rule2.ts | 11 +++ linter-4.2/test_rules/rule2.ts.autofix.json | 28 ++++++ linter-4.2/test_rules/rule2.ts.relax.json | 25 ++++++ linter-4.2/test_rules/rule2.ts.strict.json | 25 ++++++ linter-4.2/test_rules/rule21.ts | 23 +++++ linter-4.2/test_rules/rule21.ts.autofix.json | 20 +++++ linter-4.2/test_rules/rule21.ts.relax.json | 18 ++++ linter-4.2/test_rules/rule21.ts.strict.json | 18 ++++ linter-4.2/test_rules/rule22.ts | 7 ++ linter-4.2/test_rules/rule22.ts.autofix.json | 20 +++++ linter-4.2/test_rules/rule22.ts.relax.json | 18 ++++ linter-4.2/test_rules/rule22.ts.strict.json | 18 ++++ linter-4.2/test_rules/rule25.ts | 31 +++++++ linter-4.2/test_rules/rule25.ts.autofix.json | 28 ++++++ linter-4.2/test_rules/rule25.ts.relax.json | 3 + linter-4.2/test_rules/rule25.ts.strict.json | 25 ++++++ linter-4.2/test_rules/rule27.ts | 15 ++++ linter-4.2/test_rules/rule27.ts.autofix.json | 12 +++ linter-4.2/test_rules/rule27.ts.relax.json | 11 +++ linter-4.2/test_rules/rule27.ts.strict.json | 11 +++ linter-4.2/test_rules/rule28.ts | 5 ++ linter-4.2/test_rules/rule28.ts.autofix.json | 20 +++++ linter-4.2/test_rules/rule28.ts.relax.json | 18 ++++ linter-4.2/test_rules/rule28.ts.strict.json | 18 ++++ linter-4.2/test_rules/rule29.ts | 7 ++ linter-4.2/test_rules/rule29.ts.autofix.json | 26 ++++++ linter-4.2/test_rules/rule29.ts.relax.json | 3 + linter-4.2/test_rules/rule29.ts.strict.json | 11 +++ linter-4.2/test_rules/rule3.ts | 8 ++ linter-4.2/test_rules/rule3.ts.autofix.json | 12 +++ linter-4.2/test_rules/rule3.ts.relax.json | 3 + linter-4.2/test_rules/rule3.ts.strict.json | 11 +++ linter-4.2/test_rules/rule30.ts | 9 ++ linter-4.2/test_rules/rule30.ts.autofix.json | 3 + linter-4.2/test_rules/rule30.ts.relax.json | 3 + linter-4.2/test_rules/rule30.ts.strict.json | 3 + linter-4.2/test_rules/rule31.ts | 24 +++++ linter-4.2/test_rules/rule31.ts.autofix.json | 34 +++++++ linter-4.2/test_rules/rule31.ts.relax.json | 32 +++++++ linter-4.2/test_rules/rule31.ts.strict.json | 32 +++++++ linter-4.2/test_rules/rule32.ts | 57 ++++++++++++ linter-4.2/test_rules/rule32.ts.autofix.json | 34 +++++++ linter-4.2/test_rules/rule32.ts.relax.json | 32 +++++++ linter-4.2/test_rules/rule32.ts.strict.json | 32 +++++++ linter-4.2/test_rules/rule34.ts | 13 +++ linter-4.2/test_rules/rule34.ts.autofix.json | 20 +++++ linter-4.2/test_rules/rule34.ts.relax.json | 18 ++++ linter-4.2/test_rules/rule34.ts.strict.json | 18 ++++ linter-4.2/test_rules/rule35.ts | 31 +++++++ linter-4.2/test_rules/rule35.ts.autofix.json | 26 ++++++ linter-4.2/test_rules/rule35.ts.relax.json | 25 ++++++ linter-4.2/test_rules/rule35.ts.strict.json | 25 ++++++ linter-4.2/test_rules/rule37.ts | 3 + linter-4.2/test_rules/rule37.ts.autofix.json | 12 +++ linter-4.2/test_rules/rule37.ts.relax.json | 11 +++ linter-4.2/test_rules/rule37.ts.strict.json | 11 +++ linter-4.2/test_rules/rule38.ts | 53 +++++++++++ linter-4.2/test_rules/rule38.ts.autofix.json | 3 + linter-4.2/test_rules/rule38.ts.relax.json | 3 + linter-4.2/test_rules/rule38.ts.strict.json | 3 + linter-4.2/test_rules/rule4.ts | 2 + linter-4.2/test_rules/rule4.ts.autofix.json | 34 +++++++ linter-4.2/test_rules/rule4.ts.relax.json | 3 + linter-4.2/test_rules/rule4.ts.strict.json | 32 +++++++ linter-4.2/test_rules/rule40.ts | 15 ++++ linter-4.2/test_rules/rule40.ts.autofix.json | 28 ++++++ linter-4.2/test_rules/rule40.ts.relax.json | 25 ++++++ linter-4.2/test_rules/rule40.ts.strict.json | 25 ++++++ linter-4.2/test_rules/rule43.ts | 9 ++ linter-4.2/test_rules/rule43.ts.autofix.json | 28 ++++++ linter-4.2/test_rules/rule43.ts.relax.json | 25 ++++++ linter-4.2/test_rules/rule43.ts.strict.json | 25 ++++++ linter-4.2/test_rules/rule45.ts | 8 ++ linter-4.2/test_rules/rule45.ts.autofix.json | 12 +++ linter-4.2/test_rules/rule45.ts.relax.json | 11 +++ linter-4.2/test_rules/rule45.ts.strict.json | 11 +++ linter-4.2/test_rules/rule46.ts | 7 ++ linter-4.2/test_rules/rule46.ts.autofix.json | 19 ++++ linter-4.2/test_rules/rule46.ts.relax.json | 3 + linter-4.2/test_rules/rule46.ts.strict.json | 11 +++ linter-4.2/test_rules/rule49.ts | 9 ++ linter-4.2/test_rules/rule49.ts.autofix.json | 12 +++ linter-4.2/test_rules/rule49.ts.relax.json | 3 + linter-4.2/test_rules/rule49.ts.strict.json | 11 +++ linter-4.2/test_rules/rule5.ts | 19 ++++ linter-4.2/test_rules/rule5.ts.autofix.json | 28 ++++++ linter-4.2/test_rules/rule5.ts.relax.json | 11 +++ linter-4.2/test_rules/rule5.ts.strict.json | 25 ++++++ linter-4.2/test_rules/rule50.ts | 11 +++ linter-4.2/test_rules/rule50.ts.autofix.json | 28 ++++++ linter-4.2/test_rules/rule50.ts.relax.json | 18 ++++ linter-4.2/test_rules/rule50.ts.strict.json | 25 ++++++ linter-4.2/test_rules/rule51.ts | 15 ++++ linter-4.2/test_rules/rule51.ts.autofix.json | 12 +++ linter-4.2/test_rules/rule51.ts.relax.json | 11 +++ linter-4.2/test_rules/rule51.ts.strict.json | 11 +++ linter-4.2/test_rules/rule52.ts | 20 +++++ linter-4.2/test_rules/rule52.ts.autofix.json | 58 ++++++++++++ linter-4.2/test_rules/rule52.ts.relax.json | 18 ++++ linter-4.2/test_rules/rule52.ts.strict.json | 39 ++++++++ linter-4.2/test_rules/rule53.ts | 24 +++++ linter-4.2/test_rules/rule53.ts.autofix.json | 27 ++++++ linter-4.2/test_rules/rule53.ts.relax.json | 3 + linter-4.2/test_rules/rule53.ts.strict.json | 18 ++++ linter-4.2/test_rules/rule55.ts | 18 ++++ linter-4.2/test_rules/rule55.ts.autofix.json | 52 +++++++++++ linter-4.2/test_rules/rule55.ts.relax.json | 46 ++++++++++ linter-4.2/test_rules/rule55.ts.strict.json | 46 ++++++++++ linter-4.2/test_rules/rule59.ts | 15 ++++ linter-4.2/test_rules/rule59.ts.autofix.json | 20 +++++ linter-4.2/test_rules/rule59.ts.relax.json | 18 ++++ linter-4.2/test_rules/rule59.ts.strict.json | 18 ++++ linter-4.2/test_rules/rule60.ts | 13 +++ linter-4.2/test_rules/rule60.ts.autofix.json | 20 +++++ linter-4.2/test_rules/rule60.ts.relax.json | 18 ++++ linter-4.2/test_rules/rule60.ts.strict.json | 18 ++++ linter-4.2/test_rules/rule63.ts | 15 ++++ linter-4.2/test_rules/rule63.ts.autofix.json | 28 ++++++ linter-4.2/test_rules/rule63.ts.relax.json | 25 ++++++ linter-4.2/test_rules/rule63.ts.strict.json | 25 ++++++ linter-4.2/test_rules/rule65.ts | 9 ++ linter-4.2/test_rules/rule65.ts.autofix.json | 20 +++++ linter-4.2/test_rules/rule65.ts.relax.json | 18 ++++ linter-4.2/test_rules/rule65.ts.strict.json | 18 ++++ linter-4.2/test_rules/rule66.ts | 8 ++ linter-4.2/test_rules/rule66.ts.autofix.json | 12 +++ linter-4.2/test_rules/rule66.ts.relax.json | 11 +++ linter-4.2/test_rules/rule66.ts.strict.json | 11 +++ linter-4.2/test_rules/rule69.ts | 20 +++++ linter-4.2/test_rules/rule69.ts.autofix.json | 52 +++++++++++ linter-4.2/test_rules/rule69.ts.relax.json | 25 ++++++ linter-4.2/test_rules/rule69.ts.strict.json | 46 ++++++++++ linter-4.2/test_rules/rule71.ts | 16 ++++ linter-4.2/test_rules/rule71.ts.autofix.json | 12 +++ linter-4.2/test_rules/rule71.ts.relax.json | 11 +++ linter-4.2/test_rules/rule71.ts.strict.json | 11 +++ linter-4.2/test_rules/rule74.ts | 20 +++++ linter-4.2/test_rules/rule74.ts.autofix.json | 12 +++ linter-4.2/test_rules/rule74.ts.relax.json | 3 + linter-4.2/test_rules/rule74.ts.strict.json | 11 +++ linter-4.2/test_rules/rule76.ts | 10 +++ linter-4.2/test_rules/rule76.ts.autofix.json | 12 +++ linter-4.2/test_rules/rule76.ts.relax.json | 3 + linter-4.2/test_rules/rule76.ts.strict.json | 11 +++ linter-4.2/test_rules/rule79.ts | 14 +++ linter-4.2/test_rules/rule79.ts.autofix.json | 27 ++++++ linter-4.2/test_rules/rule79.ts.relax.json | 11 +++ linter-4.2/test_rules/rule79.ts.strict.json | 18 ++++ linter-4.2/test_rules/rule8.ts | 13 +++ linter-4.2/test_rules/rule8.ts.autofix.json | 20 +++++ linter-4.2/test_rules/rule8.ts.relax.json | 18 ++++ linter-4.2/test_rules/rule8.ts.strict.json | 18 ++++ linter-4.2/test_rules/rule80.ts | 10 +++ linter-4.2/test_rules/rule80.ts.autofix.json | 12 +++ linter-4.2/test_rules/rule80.ts.relax.json | 11 +++ linter-4.2/test_rules/rule80.ts.strict.json | 11 +++ linter-4.2/test_rules/rule82.ts | 9 ++ linter-4.2/test_rules/rule82.ts.autofix.json | 12 +++ linter-4.2/test_rules/rule82.ts.relax.json | 3 + linter-4.2/test_rules/rule82.ts.strict.json | 11 +++ linter-4.2/test_rules/rule83.ts | 13 +++ linter-4.2/test_rules/rule83.ts.autofix.json | 20 +++++ linter-4.2/test_rules/rule83.ts.relax.json | 18 ++++ linter-4.2/test_rules/rule83.ts.strict.json | 18 ++++ linter-4.2/test_rules/rule84.ts | 7 ++ linter-4.2/test_rules/rule84.ts.autofix.json | 12 +++ linter-4.2/test_rules/rule84.ts.relax.json | 11 +++ linter-4.2/test_rules/rule84.ts.strict.json | 11 +++ linter-4.2/test_rules/rule87.ts | 3 + linter-4.2/test_rules/rule87.ts.autofix.json | 34 +++++++ linter-4.2/test_rules/rule87.ts.relax.json | 3 + linter-4.2/test_rules/rule87.ts.strict.json | 18 ++++ linter-4.2/test_rules/rule90.ts | 37 ++++++++ linter-4.2/test_rules/rule90.ts.autofix.json | 20 +++++ linter-4.2/test_rules/rule90.ts.relax.json | 3 + linter-4.2/test_rules/rule90.ts.strict.json | 18 ++++ linter-4.2/test_rules/rule91.ts | 22 +++++ linter-4.2/test_rules/rule91.ts.autofix.json | 20 +++++ linter-4.2/test_rules/rule91.ts.relax.json | 18 ++++ linter-4.2/test_rules/rule91.ts.strict.json | 18 ++++ linter-4.2/test_rules/rule92.ts | 21 +++++ linter-4.2/test_rules/rule92.ts.autofix.json | 12 +++ linter-4.2/test_rules/rule92.ts.relax.json | 3 + linter-4.2/test_rules/rule92.ts.strict.json | 11 +++ linter-4.2/test_rules/rule93.ts | 27 ++++++ linter-4.2/test_rules/rule93.ts.autofix.json | 12 +++ linter-4.2/test_rules/rule93.ts.relax.json | 11 +++ linter-4.2/test_rules/rule93.ts.strict.json | 11 +++ linter-4.2/test_rules/rule94.ts | 22 +++++ linter-4.2/test_rules/rule94.ts.autofix.json | 28 ++++++ linter-4.2/test_rules/rule94.ts.relax.json | 18 ++++ linter-4.2/test_rules/rule94.ts.strict.json | 25 ++++++ linter-4.2/test_rules/rule96.ts | 48 ++++++++++ linter-4.2/test_rules/rule96.ts.autofix.json | 20 +++++ linter-4.2/test_rules/rule96.ts.relax.json | 18 ++++ linter-4.2/test_rules/rule96.ts.strict.json | 18 ++++ linter-4.2/test_rules/rule97.ts | 30 +++++++ linter-4.2/test_rules/rule97.ts.autofix.json | 20 +++++ linter-4.2/test_rules/rule97.ts.relax.json | 11 +++ linter-4.2/test_rules/rule97.ts.strict.json | 18 ++++ linter-4.2/test_rules/rule99.ts | 48 ++++++++++ linter-4.2/test_rules/rule99.ts.autofix.json | 52 +++++++++++ linter-4.2/test_rules/rule99.ts.relax.json | 46 ++++++++++ linter-4.2/test_rules/rule99.ts.strict.json | 46 ++++++++++ linter/.gitignore | 1 + linter/package.json | 6 +- .../{test => scripts}/update-test-results.bat | 0 .../{test => scripts}/update-test-results.mjs | 51 ++++++----- .../{test => scripts}/update-test-results.sh | 0 linter/src/FaultAttrs.ts | 2 +- linter/src/TestRunner.ts | 59 ++++++------ linter/src/utils/TsUtils.ts | 11 +-- linter/test/dynamic_lib.d.ts | 21 +++++ linter/test/dynamic_object_literals.ts | 21 ++++- linter/test_rules/rule1.ts.autofix.json | 49 +++------- linter/test_rules/rule102.ts.autofix.json | 16 +++- linter/test_rules/rule102.ts.relax.json | 16 +++- linter/test_rules/rule102.ts.strict.json | 16 +++- linter/test_rules/rule103.ts.autofix.json | 20 ++++- linter/test_rules/rule103.ts.strict.json | 20 ++++- linter/test_rules/rule106.ts.autofix.json | 17 +++- linter/test_rules/rule106.ts.relax.json | 17 +++- linter/test_rules/rule106.ts.strict.json | 17 +++- linter/test_rules/rule139.ts.autofix.json | 22 +++++ linter/test_rules/rule139.ts.relax.json | 21 +++++ linter/test_rules/rule139.ts.strict.json | 21 +++++ linter/test_rules/rule140.ts.autofix.json | 22 +++++ linter/test_rules/rule140.ts.relax.json | 21 +++++ linter/test_rules/rule140.ts.strict.json | 21 +++++ linter/test_rules/rule147.ts.autofix.json | 17 +++- linter/test_rules/rule147.ts.strict.json | 17 +++- linter/test_rules/rule17.ts.autofix.json | 21 +++-- linter/test_rules/rule29.ts.autofix.json | 21 +++-- linter/test_rules/rule31.ts.autofix.json | 18 +++- linter/test_rules/rule31.ts.relax.json | 18 +++- linter/test_rules/rule31.ts.strict.json | 18 +++- linter/test_rules/rule32.ts.autofix.json | 18 +++- linter/test_rules/rule32.ts.relax.json | 18 +++- linter/test_rules/rule32.ts.strict.json | 18 +++- linter/test_rules/rule35.ts.autofix.json | 16 +++- linter/test_rules/rule35.ts.relax.json | 16 +++- linter/test_rules/rule35.ts.strict.json | 16 +++- linter/test_rules/rule4.ts.autofix.json | 18 +++- linter/test_rules/rule4.ts.strict.json | 18 +++- linter/test_rules/rule52.ts.autofix.json | 35 +++----- 419 files changed, 8142 insertions(+), 234 deletions(-) rename linter-4.2/{test => scripts}/update-test-results.bat (100%) rename linter-4.2/{test => scripts}/update-test-results.mjs (68%) rename linter-4.2/{test => scripts}/update-test-results.sh (100%) create mode 100644 linter-4.2/test_rules/rule1.ts create mode 100644 linter-4.2/test_rules/rule1.ts.autofix.json create mode 100644 linter-4.2/test_rules/rule1.ts.relax.json create mode 100644 linter-4.2/test_rules/rule1.ts.strict.json create mode 100644 linter-4.2/test_rules/rule102.ts create mode 100644 linter-4.2/test_rules/rule102.ts.autofix.json create mode 100644 linter-4.2/test_rules/rule102.ts.relax.json create mode 100644 linter-4.2/test_rules/rule102.ts.strict.json create mode 100644 linter-4.2/test_rules/rule103.ts create mode 100644 linter-4.2/test_rules/rule103.ts.autofix.json create mode 100644 linter-4.2/test_rules/rule103.ts.relax.json create mode 100644 linter-4.2/test_rules/rule103.ts.strict.json create mode 100644 linter-4.2/test_rules/rule104.ts create mode 100644 linter-4.2/test_rules/rule104.ts.autofix.json create mode 100644 linter-4.2/test_rules/rule104.ts.relax.json create mode 100644 linter-4.2/test_rules/rule104.ts.strict.json create mode 100644 linter-4.2/test_rules/rule105.ts create mode 100644 linter-4.2/test_rules/rule105.ts.autofix.json create mode 100644 linter-4.2/test_rules/rule105.ts.relax.json create mode 100644 linter-4.2/test_rules/rule105.ts.strict.json create mode 100644 linter-4.2/test_rules/rule106.ts create mode 100644 linter-4.2/test_rules/rule106.ts.autofix.json create mode 100644 linter-4.2/test_rules/rule106.ts.relax.json create mode 100644 linter-4.2/test_rules/rule106.ts.strict.json create mode 100644 linter-4.2/test_rules/rule109.ts create mode 100644 linter-4.2/test_rules/rule109.ts.autofix.json create mode 100644 linter-4.2/test_rules/rule109.ts.relax.json create mode 100644 linter-4.2/test_rules/rule109.ts.strict.json create mode 100644 linter-4.2/test_rules/rule111.ts create mode 100644 linter-4.2/test_rules/rule111.ts.autofix.json create mode 100644 linter-4.2/test_rules/rule111.ts.relax.json create mode 100644 linter-4.2/test_rules/rule111.ts.strict.json create mode 100644 linter-4.2/test_rules/rule113.ts create mode 100644 linter-4.2/test_rules/rule113.ts.autofix.json create mode 100644 linter-4.2/test_rules/rule113.ts.relax.json create mode 100644 linter-4.2/test_rules/rule113.ts.strict.json create mode 100644 linter-4.2/test_rules/rule114.ts create mode 100644 linter-4.2/test_rules/rule114.ts.autofix.json create mode 100644 linter-4.2/test_rules/rule114.ts.relax.json create mode 100644 linter-4.2/test_rules/rule114.ts.strict.json create mode 100644 linter-4.2/test_rules/rule116.ts create mode 100644 linter-4.2/test_rules/rule116.ts.autofix.json create mode 100644 linter-4.2/test_rules/rule116.ts.relax.json create mode 100644 linter-4.2/test_rules/rule116.ts.strict.json create mode 100644 linter-4.2/test_rules/rule118.ts create mode 100644 linter-4.2/test_rules/rule118.ts.autofix.json create mode 100644 linter-4.2/test_rules/rule118.ts.relax.json create mode 100644 linter-4.2/test_rules/rule118.ts.strict.json create mode 100644 linter-4.2/test_rules/rule119.ts create mode 100644 linter-4.2/test_rules/rule119.ts.autofix.json create mode 100644 linter-4.2/test_rules/rule119.ts.relax.json create mode 100644 linter-4.2/test_rules/rule119.ts.strict.json create mode 100644 linter-4.2/test_rules/rule120.ts create mode 100644 linter-4.2/test_rules/rule120.ts.autofix.json create mode 100644 linter-4.2/test_rules/rule120.ts.relax.json create mode 100644 linter-4.2/test_rules/rule120.ts.strict.json create mode 100644 linter-4.2/test_rules/rule121.ts create mode 100644 linter-4.2/test_rules/rule121.ts.autofix.json create mode 100644 linter-4.2/test_rules/rule121.ts.relax.json create mode 100644 linter-4.2/test_rules/rule121.ts.strict.json create mode 100644 linter-4.2/test_rules/rule125.ts create mode 100644 linter-4.2/test_rules/rule125.ts.autofix.json create mode 100644 linter-4.2/test_rules/rule125.ts.relax.json create mode 100644 linter-4.2/test_rules/rule125.ts.strict.json create mode 100644 linter-4.2/test_rules/rule126.ts create mode 100644 linter-4.2/test_rules/rule126.ts.autofix.json create mode 100644 linter-4.2/test_rules/rule126.ts.relax.json create mode 100644 linter-4.2/test_rules/rule126.ts.strict.json create mode 100644 linter-4.2/test_rules/rule127.ts create mode 100644 linter-4.2/test_rules/rule127.ts.autofix.json create mode 100644 linter-4.2/test_rules/rule127.ts.relax.json create mode 100644 linter-4.2/test_rules/rule127.ts.strict.json create mode 100644 linter-4.2/test_rules/rule128.ts create mode 100644 linter-4.2/test_rules/rule128.ts.autofix.json create mode 100644 linter-4.2/test_rules/rule128.ts.relax.json create mode 100644 linter-4.2/test_rules/rule128.ts.strict.json create mode 100644 linter-4.2/test_rules/rule129.ts create mode 100644 linter-4.2/test_rules/rule129.ts.autofix.json create mode 100644 linter-4.2/test_rules/rule129.ts.relax.json create mode 100644 linter-4.2/test_rules/rule129.ts.strict.json create mode 100644 linter-4.2/test_rules/rule13.ts create mode 100644 linter-4.2/test_rules/rule13.ts.autofix.json create mode 100644 linter-4.2/test_rules/rule13.ts.relax.json create mode 100644 linter-4.2/test_rules/rule13.ts.strict.json create mode 100644 linter-4.2/test_rules/rule130.ts create mode 100644 linter-4.2/test_rules/rule130.ts.autofix.json create mode 100644 linter-4.2/test_rules/rule130.ts.relax.json create mode 100644 linter-4.2/test_rules/rule130.ts.strict.json create mode 100644 linter-4.2/test_rules/rule132.ts create mode 100644 linter-4.2/test_rules/rule132.ts.autofix.json create mode 100644 linter-4.2/test_rules/rule132.ts.relax.json create mode 100644 linter-4.2/test_rules/rule132.ts.strict.json create mode 100644 linter-4.2/test_rules/rule133.ts create mode 100644 linter-4.2/test_rules/rule133.ts.autofix.json create mode 100644 linter-4.2/test_rules/rule133.ts.relax.json create mode 100644 linter-4.2/test_rules/rule133.ts.strict.json create mode 100644 linter-4.2/test_rules/rule134.ts create mode 100644 linter-4.2/test_rules/rule134.ts.autofix.json create mode 100644 linter-4.2/test_rules/rule134.ts.relax.json create mode 100644 linter-4.2/test_rules/rule134.ts.strict.json create mode 100644 linter-4.2/test_rules/rule135.ts create mode 100644 linter-4.2/test_rules/rule135.ts.autofix.json create mode 100644 linter-4.2/test_rules/rule135.ts.relax.json create mode 100644 linter-4.2/test_rules/rule135.ts.strict.json create mode 100644 linter-4.2/test_rules/rule136.ts create mode 100644 linter-4.2/test_rules/rule136.ts.autofix.json create mode 100644 linter-4.2/test_rules/rule136.ts.relax.json create mode 100644 linter-4.2/test_rules/rule136.ts.strict.json create mode 100644 linter-4.2/test_rules/rule137.ts create mode 100644 linter-4.2/test_rules/rule137.ts.autofix.json create mode 100644 linter-4.2/test_rules/rule137.ts.relax.json create mode 100644 linter-4.2/test_rules/rule137.ts.strict.json create mode 100644 linter-4.2/test_rules/rule138.ts create mode 100644 linter-4.2/test_rules/rule138.ts.autofix.json create mode 100644 linter-4.2/test_rules/rule138.ts.relax.json create mode 100644 linter-4.2/test_rules/rule138.ts.strict.json create mode 100644 linter-4.2/test_rules/rule139.ts create mode 100644 linter-4.2/test_rules/rule139.ts.autofix.json create mode 100644 linter-4.2/test_rules/rule139.ts.relax.json create mode 100644 linter-4.2/test_rules/rule139.ts.strict.json create mode 100644 linter-4.2/test_rules/rule14.ts create mode 100644 linter-4.2/test_rules/rule14.ts.autofix.json create mode 100644 linter-4.2/test_rules/rule14.ts.relax.json create mode 100644 linter-4.2/test_rules/rule14.ts.strict.json create mode 100644 linter-4.2/test_rules/rule140.ts create mode 100644 linter-4.2/test_rules/rule140.ts.autofix.json create mode 100644 linter-4.2/test_rules/rule140.ts.relax.json create mode 100644 linter-4.2/test_rules/rule140.ts.strict.json create mode 100644 linter-4.2/test_rules/rule141.ts create mode 100644 linter-4.2/test_rules/rule141.ts.autofix.json create mode 100644 linter-4.2/test_rules/rule141.ts.relax.json create mode 100644 linter-4.2/test_rules/rule141.ts.strict.json create mode 100644 linter-4.2/test_rules/rule142.ts create mode 100644 linter-4.2/test_rules/rule142.ts.autofix.json create mode 100644 linter-4.2/test_rules/rule142.ts.relax.json create mode 100644 linter-4.2/test_rules/rule142.ts.strict.json create mode 100644 linter-4.2/test_rules/rule145.ts create mode 100644 linter-4.2/test_rules/rule145.ts.autofix.json create mode 100644 linter-4.2/test_rules/rule145.ts.relax.json create mode 100644 linter-4.2/test_rules/rule145.ts.strict.json create mode 100644 linter-4.2/test_rules/rule146.ts create mode 100644 linter-4.2/test_rules/rule146.ts.autofix.json create mode 100644 linter-4.2/test_rules/rule146.ts.relax.json create mode 100644 linter-4.2/test_rules/rule146.ts.strict.json create mode 100644 linter-4.2/test_rules/rule147.ts create mode 100644 linter-4.2/test_rules/rule147.ts.autofix.json create mode 100644 linter-4.2/test_rules/rule147.ts.relax.json create mode 100644 linter-4.2/test_rules/rule147.ts.strict.json create mode 100644 linter-4.2/test_rules/rule148.ts create mode 100644 linter-4.2/test_rules/rule148.ts.autofix.json create mode 100644 linter-4.2/test_rules/rule148.ts.relax.json create mode 100644 linter-4.2/test_rules/rule148.ts.strict.json create mode 100644 linter-4.2/test_rules/rule15.ts create mode 100644 linter-4.2/test_rules/rule15.ts.autofix.json create mode 100644 linter-4.2/test_rules/rule15.ts.relax.json create mode 100644 linter-4.2/test_rules/rule15.ts.strict.json create mode 100644 linter-4.2/test_rules/rule17.ts create mode 100644 linter-4.2/test_rules/rule17.ts.autofix.json create mode 100644 linter-4.2/test_rules/rule17.ts.relax.json create mode 100644 linter-4.2/test_rules/rule17.ts.strict.json create mode 100644 linter-4.2/test_rules/rule19.ts create mode 100644 linter-4.2/test_rules/rule19.ts.autofix.json create mode 100644 linter-4.2/test_rules/rule19.ts.relax.json create mode 100644 linter-4.2/test_rules/rule19.ts.strict.json create mode 100644 linter-4.2/test_rules/rule2.ts create mode 100644 linter-4.2/test_rules/rule2.ts.autofix.json create mode 100644 linter-4.2/test_rules/rule2.ts.relax.json create mode 100644 linter-4.2/test_rules/rule2.ts.strict.json create mode 100644 linter-4.2/test_rules/rule21.ts create mode 100644 linter-4.2/test_rules/rule21.ts.autofix.json create mode 100644 linter-4.2/test_rules/rule21.ts.relax.json create mode 100644 linter-4.2/test_rules/rule21.ts.strict.json create mode 100644 linter-4.2/test_rules/rule22.ts create mode 100644 linter-4.2/test_rules/rule22.ts.autofix.json create mode 100644 linter-4.2/test_rules/rule22.ts.relax.json create mode 100644 linter-4.2/test_rules/rule22.ts.strict.json create mode 100644 linter-4.2/test_rules/rule25.ts create mode 100644 linter-4.2/test_rules/rule25.ts.autofix.json create mode 100644 linter-4.2/test_rules/rule25.ts.relax.json create mode 100644 linter-4.2/test_rules/rule25.ts.strict.json create mode 100644 linter-4.2/test_rules/rule27.ts create mode 100644 linter-4.2/test_rules/rule27.ts.autofix.json create mode 100644 linter-4.2/test_rules/rule27.ts.relax.json create mode 100644 linter-4.2/test_rules/rule27.ts.strict.json create mode 100644 linter-4.2/test_rules/rule28.ts create mode 100644 linter-4.2/test_rules/rule28.ts.autofix.json create mode 100644 linter-4.2/test_rules/rule28.ts.relax.json create mode 100644 linter-4.2/test_rules/rule28.ts.strict.json create mode 100644 linter-4.2/test_rules/rule29.ts create mode 100644 linter-4.2/test_rules/rule29.ts.autofix.json create mode 100644 linter-4.2/test_rules/rule29.ts.relax.json create mode 100644 linter-4.2/test_rules/rule29.ts.strict.json create mode 100644 linter-4.2/test_rules/rule3.ts create mode 100644 linter-4.2/test_rules/rule3.ts.autofix.json create mode 100644 linter-4.2/test_rules/rule3.ts.relax.json create mode 100644 linter-4.2/test_rules/rule3.ts.strict.json create mode 100644 linter-4.2/test_rules/rule30.ts create mode 100644 linter-4.2/test_rules/rule30.ts.autofix.json create mode 100644 linter-4.2/test_rules/rule30.ts.relax.json create mode 100644 linter-4.2/test_rules/rule30.ts.strict.json create mode 100644 linter-4.2/test_rules/rule31.ts create mode 100644 linter-4.2/test_rules/rule31.ts.autofix.json create mode 100644 linter-4.2/test_rules/rule31.ts.relax.json create mode 100644 linter-4.2/test_rules/rule31.ts.strict.json create mode 100644 linter-4.2/test_rules/rule32.ts create mode 100644 linter-4.2/test_rules/rule32.ts.autofix.json create mode 100644 linter-4.2/test_rules/rule32.ts.relax.json create mode 100644 linter-4.2/test_rules/rule32.ts.strict.json create mode 100644 linter-4.2/test_rules/rule34.ts create mode 100644 linter-4.2/test_rules/rule34.ts.autofix.json create mode 100644 linter-4.2/test_rules/rule34.ts.relax.json create mode 100644 linter-4.2/test_rules/rule34.ts.strict.json create mode 100644 linter-4.2/test_rules/rule35.ts create mode 100644 linter-4.2/test_rules/rule35.ts.autofix.json create mode 100644 linter-4.2/test_rules/rule35.ts.relax.json create mode 100644 linter-4.2/test_rules/rule35.ts.strict.json create mode 100644 linter-4.2/test_rules/rule37.ts create mode 100644 linter-4.2/test_rules/rule37.ts.autofix.json create mode 100644 linter-4.2/test_rules/rule37.ts.relax.json create mode 100644 linter-4.2/test_rules/rule37.ts.strict.json create mode 100644 linter-4.2/test_rules/rule38.ts create mode 100644 linter-4.2/test_rules/rule38.ts.autofix.json create mode 100644 linter-4.2/test_rules/rule38.ts.relax.json create mode 100644 linter-4.2/test_rules/rule38.ts.strict.json create mode 100644 linter-4.2/test_rules/rule4.ts create mode 100644 linter-4.2/test_rules/rule4.ts.autofix.json create mode 100644 linter-4.2/test_rules/rule4.ts.relax.json create mode 100644 linter-4.2/test_rules/rule4.ts.strict.json create mode 100644 linter-4.2/test_rules/rule40.ts create mode 100644 linter-4.2/test_rules/rule40.ts.autofix.json create mode 100644 linter-4.2/test_rules/rule40.ts.relax.json create mode 100644 linter-4.2/test_rules/rule40.ts.strict.json create mode 100644 linter-4.2/test_rules/rule43.ts create mode 100644 linter-4.2/test_rules/rule43.ts.autofix.json create mode 100644 linter-4.2/test_rules/rule43.ts.relax.json create mode 100644 linter-4.2/test_rules/rule43.ts.strict.json create mode 100644 linter-4.2/test_rules/rule45.ts create mode 100644 linter-4.2/test_rules/rule45.ts.autofix.json create mode 100644 linter-4.2/test_rules/rule45.ts.relax.json create mode 100644 linter-4.2/test_rules/rule45.ts.strict.json create mode 100644 linter-4.2/test_rules/rule46.ts create mode 100644 linter-4.2/test_rules/rule46.ts.autofix.json create mode 100644 linter-4.2/test_rules/rule46.ts.relax.json create mode 100644 linter-4.2/test_rules/rule46.ts.strict.json create mode 100644 linter-4.2/test_rules/rule49.ts create mode 100644 linter-4.2/test_rules/rule49.ts.autofix.json create mode 100644 linter-4.2/test_rules/rule49.ts.relax.json create mode 100644 linter-4.2/test_rules/rule49.ts.strict.json create mode 100644 linter-4.2/test_rules/rule5.ts create mode 100644 linter-4.2/test_rules/rule5.ts.autofix.json create mode 100644 linter-4.2/test_rules/rule5.ts.relax.json create mode 100644 linter-4.2/test_rules/rule5.ts.strict.json create mode 100644 linter-4.2/test_rules/rule50.ts create mode 100644 linter-4.2/test_rules/rule50.ts.autofix.json create mode 100644 linter-4.2/test_rules/rule50.ts.relax.json create mode 100644 linter-4.2/test_rules/rule50.ts.strict.json create mode 100644 linter-4.2/test_rules/rule51.ts create mode 100644 linter-4.2/test_rules/rule51.ts.autofix.json create mode 100644 linter-4.2/test_rules/rule51.ts.relax.json create mode 100644 linter-4.2/test_rules/rule51.ts.strict.json create mode 100644 linter-4.2/test_rules/rule52.ts create mode 100644 linter-4.2/test_rules/rule52.ts.autofix.json create mode 100644 linter-4.2/test_rules/rule52.ts.relax.json create mode 100644 linter-4.2/test_rules/rule52.ts.strict.json create mode 100644 linter-4.2/test_rules/rule53.ts create mode 100644 linter-4.2/test_rules/rule53.ts.autofix.json create mode 100644 linter-4.2/test_rules/rule53.ts.relax.json create mode 100644 linter-4.2/test_rules/rule53.ts.strict.json create mode 100644 linter-4.2/test_rules/rule55.ts create mode 100644 linter-4.2/test_rules/rule55.ts.autofix.json create mode 100644 linter-4.2/test_rules/rule55.ts.relax.json create mode 100644 linter-4.2/test_rules/rule55.ts.strict.json create mode 100644 linter-4.2/test_rules/rule59.ts create mode 100644 linter-4.2/test_rules/rule59.ts.autofix.json create mode 100644 linter-4.2/test_rules/rule59.ts.relax.json create mode 100644 linter-4.2/test_rules/rule59.ts.strict.json create mode 100644 linter-4.2/test_rules/rule60.ts create mode 100644 linter-4.2/test_rules/rule60.ts.autofix.json create mode 100644 linter-4.2/test_rules/rule60.ts.relax.json create mode 100644 linter-4.2/test_rules/rule60.ts.strict.json create mode 100644 linter-4.2/test_rules/rule63.ts create mode 100644 linter-4.2/test_rules/rule63.ts.autofix.json create mode 100644 linter-4.2/test_rules/rule63.ts.relax.json create mode 100644 linter-4.2/test_rules/rule63.ts.strict.json create mode 100644 linter-4.2/test_rules/rule65.ts create mode 100644 linter-4.2/test_rules/rule65.ts.autofix.json create mode 100644 linter-4.2/test_rules/rule65.ts.relax.json create mode 100644 linter-4.2/test_rules/rule65.ts.strict.json create mode 100644 linter-4.2/test_rules/rule66.ts create mode 100644 linter-4.2/test_rules/rule66.ts.autofix.json create mode 100644 linter-4.2/test_rules/rule66.ts.relax.json create mode 100644 linter-4.2/test_rules/rule66.ts.strict.json create mode 100644 linter-4.2/test_rules/rule69.ts create mode 100644 linter-4.2/test_rules/rule69.ts.autofix.json create mode 100644 linter-4.2/test_rules/rule69.ts.relax.json create mode 100644 linter-4.2/test_rules/rule69.ts.strict.json create mode 100644 linter-4.2/test_rules/rule71.ts create mode 100644 linter-4.2/test_rules/rule71.ts.autofix.json create mode 100644 linter-4.2/test_rules/rule71.ts.relax.json create mode 100644 linter-4.2/test_rules/rule71.ts.strict.json create mode 100644 linter-4.2/test_rules/rule74.ts create mode 100644 linter-4.2/test_rules/rule74.ts.autofix.json create mode 100644 linter-4.2/test_rules/rule74.ts.relax.json create mode 100644 linter-4.2/test_rules/rule74.ts.strict.json create mode 100644 linter-4.2/test_rules/rule76.ts create mode 100644 linter-4.2/test_rules/rule76.ts.autofix.json create mode 100644 linter-4.2/test_rules/rule76.ts.relax.json create mode 100644 linter-4.2/test_rules/rule76.ts.strict.json create mode 100644 linter-4.2/test_rules/rule79.ts create mode 100644 linter-4.2/test_rules/rule79.ts.autofix.json create mode 100644 linter-4.2/test_rules/rule79.ts.relax.json create mode 100644 linter-4.2/test_rules/rule79.ts.strict.json create mode 100644 linter-4.2/test_rules/rule8.ts create mode 100644 linter-4.2/test_rules/rule8.ts.autofix.json create mode 100644 linter-4.2/test_rules/rule8.ts.relax.json create mode 100644 linter-4.2/test_rules/rule8.ts.strict.json create mode 100644 linter-4.2/test_rules/rule80.ts create mode 100644 linter-4.2/test_rules/rule80.ts.autofix.json create mode 100644 linter-4.2/test_rules/rule80.ts.relax.json create mode 100644 linter-4.2/test_rules/rule80.ts.strict.json create mode 100644 linter-4.2/test_rules/rule82.ts create mode 100644 linter-4.2/test_rules/rule82.ts.autofix.json create mode 100644 linter-4.2/test_rules/rule82.ts.relax.json create mode 100644 linter-4.2/test_rules/rule82.ts.strict.json create mode 100644 linter-4.2/test_rules/rule83.ts create mode 100644 linter-4.2/test_rules/rule83.ts.autofix.json create mode 100644 linter-4.2/test_rules/rule83.ts.relax.json create mode 100644 linter-4.2/test_rules/rule83.ts.strict.json create mode 100644 linter-4.2/test_rules/rule84.ts create mode 100644 linter-4.2/test_rules/rule84.ts.autofix.json create mode 100644 linter-4.2/test_rules/rule84.ts.relax.json create mode 100644 linter-4.2/test_rules/rule84.ts.strict.json create mode 100644 linter-4.2/test_rules/rule87.ts create mode 100644 linter-4.2/test_rules/rule87.ts.autofix.json create mode 100644 linter-4.2/test_rules/rule87.ts.relax.json create mode 100644 linter-4.2/test_rules/rule87.ts.strict.json create mode 100644 linter-4.2/test_rules/rule90.ts create mode 100644 linter-4.2/test_rules/rule90.ts.autofix.json create mode 100644 linter-4.2/test_rules/rule90.ts.relax.json create mode 100644 linter-4.2/test_rules/rule90.ts.strict.json create mode 100644 linter-4.2/test_rules/rule91.ts create mode 100644 linter-4.2/test_rules/rule91.ts.autofix.json create mode 100644 linter-4.2/test_rules/rule91.ts.relax.json create mode 100644 linter-4.2/test_rules/rule91.ts.strict.json create mode 100644 linter-4.2/test_rules/rule92.ts create mode 100644 linter-4.2/test_rules/rule92.ts.autofix.json create mode 100644 linter-4.2/test_rules/rule92.ts.relax.json create mode 100644 linter-4.2/test_rules/rule92.ts.strict.json create mode 100644 linter-4.2/test_rules/rule93.ts create mode 100644 linter-4.2/test_rules/rule93.ts.autofix.json create mode 100644 linter-4.2/test_rules/rule93.ts.relax.json create mode 100644 linter-4.2/test_rules/rule93.ts.strict.json create mode 100644 linter-4.2/test_rules/rule94.ts create mode 100644 linter-4.2/test_rules/rule94.ts.autofix.json create mode 100644 linter-4.2/test_rules/rule94.ts.relax.json create mode 100644 linter-4.2/test_rules/rule94.ts.strict.json create mode 100644 linter-4.2/test_rules/rule96.ts create mode 100644 linter-4.2/test_rules/rule96.ts.autofix.json create mode 100644 linter-4.2/test_rules/rule96.ts.relax.json create mode 100644 linter-4.2/test_rules/rule96.ts.strict.json create mode 100644 linter-4.2/test_rules/rule97.ts create mode 100644 linter-4.2/test_rules/rule97.ts.autofix.json create mode 100644 linter-4.2/test_rules/rule97.ts.relax.json create mode 100644 linter-4.2/test_rules/rule97.ts.strict.json create mode 100644 linter-4.2/test_rules/rule99.ts create mode 100644 linter-4.2/test_rules/rule99.ts.autofix.json create mode 100644 linter-4.2/test_rules/rule99.ts.relax.json create mode 100644 linter-4.2/test_rules/rule99.ts.strict.json rename linter/{test => scripts}/update-test-results.bat (100%) rename linter/{test => scripts}/update-test-results.mjs (68%) rename linter/{test => scripts}/update-test-results.sh (100%) mode change 100755 => 100644 diff --git a/linter-4.2/.gitignore b/linter-4.2/.gitignore index 4797db793..3feb73341 100644 --- a/linter-4.2/.gitignore +++ b/linter-4.2/.gitignore @@ -8,4 +8,5 @@ cookbook_convertor/md .vscode .cache test/**/results +test_rules/**/results package-lock.json \ No newline at end of file diff --git a/linter-4.2/package.json b/linter-4.2/package.json index e01513b09..651fc138f 100644 --- a/linter-4.2/package.json +++ b/linter-4.2/package.json @@ -17,7 +17,10 @@ "build": "npm run clean && npm run compile && npm run webpack && npm run pack:linter", "postinstall": "npm run build", "pack:linter": "rimraf bundle && mkdir bundle && npm pack --pack-destination bundle", - "test": "npm run compile && rimraf test/results && node build/src/TestRunner.js test" + "test": "npm run compile && rimraf test/results test_rules/results && node build/src/TestRunner.js test test_rules", + "test_main": "npm run compile && rimraf test/results && node build/src/TestRunner.js test", + "test_rules": "npm run compile && rimraf test_rules/results && node build/src/TestRunner.js test_rules", + "update-tests": "node scripts/update-test-results.mjs test test_rules" }, "devDependencies": { "@types/node": "18.11.7", diff --git a/linter-4.2/test/update-test-results.bat b/linter-4.2/scripts/update-test-results.bat similarity index 100% rename from linter-4.2/test/update-test-results.bat rename to linter-4.2/scripts/update-test-results.bat diff --git a/linter-4.2/test/update-test-results.mjs b/linter-4.2/scripts/update-test-results.mjs similarity index 68% rename from linter-4.2/test/update-test-results.mjs rename to linter-4.2/scripts/update-test-results.mjs index b750c0706..dc579e424 100644 --- a/linter-4.2/test/update-test-results.mjs +++ b/linter-4.2/scripts/update-test-results.mjs @@ -34,8 +34,17 @@ const AUTOFIX_SKIP_EXT = '.autofix.skip'; const DIFF_EXT = '.diff'; const RESULTS_DIR = 'results' +let testDirs = []; + // forces to update all tests regardless of whether there was diff in a test result -const force_update = process.argv.includes('--force'); +const force_update = false; + +for (let arg of process.argv.slice(2)) { + if (arg === '--force') + force_update = true; + else + testDirs.push(arg); +} const DEFAULT_COPYRIGHT = [ "Copyright (c) 2023-2023 Huawei Device Co., Ltd.", @@ -61,25 +70,25 @@ function readTestFile(filePath) { } } -function updateTest(testFile, mode) { +function updateTest(testDir, testFile, mode) { let resultExt = RESULT_EXT[mode]; let testFileWithExt = testFile + resultExt; // Do not update autofix result if test is skipped - if (mode === Mode.AUTOFIX && fs.existsSync(testFile + AUTOFIX_SKIP_EXT)) { + if (mode === Mode.AUTOFIX && fs.existsSync(path.join(testDir, testFileWithExt + AUTOFIX_SKIP_EXT))) { return; } // Update test result when 'diff' exists or the 'force' option is enabled. - if (!fs.existsSync(path.join(RESULTS_DIR, testFileWithExt + DIFF_EXT)) && !force_update) { + if (!fs.existsSync(path.join(testDir, RESULTS_DIR, testFileWithExt + DIFF_EXT)) && !force_update) { return; } - let expectedResult = readTestFile(testFileWithExt); + let expectedResult = readTestFile(path.join(testDir, testFileWithExt)); const copyright = expectedResult?.copyright ?? DEFAULT_COPYRIGHT; - let actualResult = readTestFile(path.join(RESULTS_DIR, testFileWithExt)); + let actualResult = readTestFile(path.join(testDir, RESULTS_DIR, testFileWithExt)); if (!actualResult || !actualResult.nodes) { console.log(`Failed to update ${testFileWithExt}: couldn't read ACTUAL result file.`); return; @@ -87,28 +96,24 @@ function updateTest(testFile, mode) { // Write file with actual test results. let newResultJSON = JSON.stringify({ copyright, nodes: actualResult.nodes }, null, 4); - fs.writeFileSync(testFileWithExt, newResultJSON); + fs.writeFileSync(path.join(testDir, testFileWithExt), newResultJSON); console.log(`Updated ${testFileWithExt}`); } -if (!fs.existsSync(RESULTS_DIR)) { - console.log(`The ${RESULTS_DIR} dir does not exist!`); - process.exit(0); -} +for (let testDir of testDirs) { + if (!fs.existsSync(path.join(testDir, RESULTS_DIR))) continue; -// Get tests from test directory. -let testFiles = fs.readdirSync(".").filter(x => - (x.trimEnd().endsWith(TS_EXT) && !x.trimEnd().endsWith(D_TS_EXT)) || x.trimEnd().endsWith(TSX_EXT)); + // Get tests from test directory. + let testFiles = fs.readdirSync(testDir).filter(x => + (x.trimEnd().endsWith(TS_EXT) && !x.trimEnd().endsWith(D_TS_EXT)) || x.trimEnd().endsWith(TSX_EXT)); -if (!testFiles || testFiles.length == 0) { - console.log("No tests to update."); - process.exit(0); -} + if (!testFiles) continue; -// Update result for each test for Strict and Relax modes: -for (let testFile of testFiles) { - updateTest(testFile, Mode.RELAX); - updateTest(testFile, Mode.STRICT); - updateTest(testFile, Mode.AUTOFIX); + // Update result for each test for Strict and Relax modes: + for (let testFile of testFiles) { + updateTest(testDir, testFile, Mode.RELAX); + updateTest(testDir, testFile, Mode.STRICT); + updateTest(testDir, testFile, Mode.AUTOFIX); + } } \ No newline at end of file diff --git a/linter-4.2/test/update-test-results.sh b/linter-4.2/scripts/update-test-results.sh similarity index 100% rename from linter-4.2/test/update-test-results.sh rename to linter-4.2/scripts/update-test-results.sh diff --git a/linter-4.2/src/Problems.ts b/linter-4.2/src/Problems.ts index 4f9474699..7cd8809de 100644 --- a/linter-4.2/src/Problems.ts +++ b/linter-4.2/src/Problems.ts @@ -83,7 +83,6 @@ faultsAttrs[FaultID.JsxElement] = {cookBookRef: '54',}; faultsAttrs[FaultID.UnaryArithmNotNumber] = {cookBookRef: '55',}; faultsAttrs[FaultID.DeleteOperator] = {cookBookRef: '59',}; faultsAttrs[FaultID.TypeQuery] = {cookBookRef: '60',}; -// remove as rule#61: FaultID.BitOpWithWrongType => {cookBookRef: '61',}; faultsAttrs[FaultID.InstanceofUnsupported] = {cookBookRef: '65',}; faultsAttrs[FaultID.InOperator] = {cookBookRef: '66',}; faultsAttrs[FaultID.DestructuringAssignment] = {migratable: true, cookBookRef: '69',}; @@ -112,7 +111,6 @@ faultsAttrs[FaultID.ConstructorFuncs] = {cookBookRef: '106',}; faultsAttrs[FaultID.EnumMemberNonConstInit] = {cookBookRef: '111',}; faultsAttrs[FaultID.EnumMerging] = {cookBookRef: '113',}; faultsAttrs[FaultID.NamespaceAsObject] = {cookBookRef: '114',}; -faultsAttrs[FaultID.ClassAsObject] = {warning: true, cookBookRef: '-1',}; faultsAttrs[FaultID.NonDeclarationInNamespace] = {cookBookRef: '116',}; faultsAttrs[FaultID.ImportFromPath] = {cookBookRef: '119',}; faultsAttrs[FaultID.TypeOnlyImport] = {migratable: true, cookBookRef: '118',}; @@ -139,7 +137,8 @@ faultsAttrs[FaultID.LimitedStdLibApi] = {cookBookRef: '144',}; faultsAttrs[FaultID.StrictDiagnostic] = {cookBookRef: '145',}; faultsAttrs[FaultID.ErrorSuppression] = {cookBookRef: '146',}; faultsAttrs[FaultID.UnsupportedDecorators] = {cookBookRef: '148',}; -faultsAttrs[FaultID.ImportAfterStatement] = {cookBookRef: '-1',}; +faultsAttrs[FaultID.ClassAsObject] = {warning: true, cookBookRef: '149',}; +faultsAttrs[FaultID.ImportAfterStatement] = {cookBookRef: '150',}; faultsAttrs[FaultID.EsObjectType] = {cookBookRef: '8'}; faultsAttrs[FaultID.EsObjectAssignment] = {cookBookRef: '8'}; faultsAttrs[FaultID.EsObjectAccess] = {cookBookRef: '8'}; diff --git a/linter-4.2/src/TestRunner.ts b/linter-4.2/src/TestRunner.ts index e065d61b6..f31ce5cbf 100644 --- a/linter-4.2/src/TestRunner.ts +++ b/linter-4.2/src/TestRunner.ts @@ -52,7 +52,7 @@ const AUTOFIX_SKIP_EXT = '.autofix.skip'; const ARGS_CONFIG_EXT = '.args.json' const DIFF_EXT = '.diff'; -function runTests(baseDir: string): number { +function runTests(testDirs: string[]): number { let hasComparisonFailures = false; // Set the IDE mode manually to enable storing information @@ -60,37 +60,36 @@ function runTests(baseDir: string): number { TypeScriptLinter.ideMode = true; TypeScriptLinter.testMode = true; - // Get tests from test directory - const testDir = baseDir ?? TEST_DIR; - const testFiles: string[] = fs.readdirSync(testDir) - .filter((x) => (x.trimEnd().endsWith(ts.Extension.Ts) && !x.trimEnd().endsWith(ts.Extension.Dts)) || x.trimEnd().endsWith(ts.Extension.Tsx)); - - if (!testFiles || testFiles.length == 0) { - logger.info('No tests to run!'); - process.exit(0); - } - let passed = 0, failed = 0; - // Run each test in Strict, Autofix, and Relax mode: - for (const testFile of testFiles) { - if (runTest(testDir, testFile, Mode.STRICT)) { - failed++; - hasComparisonFailures = true; - } - else passed++; - - if (runTest(testDir, testFile, Mode.AUTOFIX)) { - failed++; - hasComparisonFailures = true; - } - else passed++; - - if (runTest(testDir, testFile, Mode.RELAX)) { - failed++; - hasComparisonFailures = true; + // Get tests from test directory + if (!testDirs?.length) testDirs = [ TEST_DIR ]; + for (const testDir of testDirs) { + let testFiles: string[] = fs.readdirSync(testDir) + .filter((x) => (x.trimEnd().endsWith(ts.Extension.Ts) && !x.trimEnd().endsWith(ts.Extension.Dts)) || x.trimEnd().endsWith(ts.Extension.Tsx)); + + logger.info(`\nProcessing "${testDir}" directory:\n`); + + // Run each test in Strict, Autofix, and Relax mode: + for (const testFile of testFiles) { + if (runTest(testDir, testFile, Mode.STRICT)) { + failed++; + hasComparisonFailures = true; + } + else passed++; + + if (runTest(testDir, testFile, Mode.AUTOFIX)) { + failed++; + hasComparisonFailures = true; + } + else passed++; + + if (runTest(testDir, testFile, Mode.RELAX)) { + failed++; + hasComparisonFailures = true; + } + else passed++; } - else passed++; } logger.info(`\nSUMMARY: ${passed + failed} total, ${passed} passed or skipped, ${failed} failed.`); @@ -241,4 +240,4 @@ ${actualNode}`; return diff; } -runTests(process.argv[2]); \ No newline at end of file +runTests(process.argv.slice(2)); \ No newline at end of file diff --git a/linter-4.2/src/Utils.ts b/linter-4.2/src/Utils.ts index 1fc3ed1ab..4414b69bc 100644 --- a/linter-4.2/src/Utils.ts +++ b/linter-4.2/src/Utils.ts @@ -1180,15 +1180,12 @@ export class TsUtils { if (type.isUnion()) { for (let compType of type.types) { - if (this.isLibraryType(compType)) { - return true; - } - - if (!this.isStdLibraryType(compType) && !this.isIntrinsicObjectType(compType) && !this.isAnyType(compType)) { - return false; + let isDynamic = this.isDynamicType(compType); + if (isDynamic || isDynamic === undefined) { + return isDynamic; } } - return undefined; + return false; } if (this.isLibraryType(type)) { diff --git a/linter-4.2/test/dynamic_lib.d.ts b/linter-4.2/test/dynamic_lib.d.ts index a9bb5c9a5..b6a9493cb 100644 --- a/linter-4.2/test/dynamic_lib.d.ts +++ b/linter-4.2/test/dynamic_lib.d.ts @@ -48,3 +48,24 @@ export let dynamic_array: Array; export declare class C1 {} export declare function f2(c: C1): void; + +export type Length = string | number | Resource; +export interface Resource { + readonly id: number; + readonly type: number; +} +export type Padding = { + top?: Length; + right?: Length; + bottom?: Length; + left?: Length; +} +export type Margin = Padding; +export interface Position { + x?: Length; + y?: Length; +} + +export function padding(value: Padding | Length): any; +export function margin(value: Margin | Length): any; +export function position(value: Position): any; \ No newline at end of file diff --git a/linter-4.2/test/dynamic_object_literals.ts b/linter-4.2/test/dynamic_object_literals.ts index 7ed1e3479..ea7f9759a 100644 --- a/linter-4.2/test/dynamic_object_literals.ts +++ b/linter-4.2/test/dynamic_object_literals.ts @@ -13,7 +13,19 @@ * limitations under the License. */ -import { I, foo, I2, I3, bar, C, getDynamicObject, dynamic_array } from "./dynamic_lib" +import { + I, + foo, + I2, + I3, + bar, + C, + getDynamicObject, + dynamic_array, + padding, + margin, + position +} from "./dynamic_lib" function main(): void { let obj: I = { @@ -67,4 +79,9 @@ function createInitProps(c: C) { } // #13483 - pass object literal to method call of exported variable -dynamic_array.splice(2, 0, {a: 1, b: '2'}); \ No newline at end of file +dynamic_array.splice(2, 0, {a: 1, b: '2'}); + +// #13550 - allow literals as property names in dynamic context +padding({'top': '0px', 'right': '5px', 'bottom': '10px', 'left': '15px'}); +margin({'top': '10px', 'right': '20px', 'bottom': '30px', 'left': '40px'}); +position({'x': '20', 'y': '40'}); \ No newline at end of file diff --git a/linter-4.2/test_rules/rule1.ts b/linter-4.2/test_rules/rule1.ts new file mode 100644 index 000000000..b0332f643 --- /dev/null +++ b/linter-4.2/test_rules/rule1.ts @@ -0,0 +1,14 @@ + +var x = {"name": 1, 2: 3} + +console.log(x["name"]) +console.log(x[2]) + +class X { + public name: number = 0 +} +let y = {name: 1} +console.log(x.name) + +let z = [1, 2, 3] +console.log(y[2]) \ No newline at end of file diff --git a/linter-4.2/test_rules/rule1.ts.autofix.json b/linter-4.2/test_rules/rule1.ts.autofix.json new file mode 100644 index 000000000..32a60bb65 --- /dev/null +++ b/linter-4.2/test_rules/rule1.ts.autofix.json @@ -0,0 +1,82 @@ +{ + "copyright": [ + "Copyright (c) 2023-2023 Huawei Device Co., Ltd.", + "Licensed under the Apache License, Version 2.0 (the 'License');", + "you may not use this file except in compliance with the License.", + "You may obtain a copy of the License at", + "", + "http://www.apache.org/licenses/LICENSE-2.0", + "", + "Unless required by applicable law or agreed to in writing, software", + "distributed under the License is distributed on an 'AS IS' BASIS,", + "WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.", + "See the License for the specific language governing permissions and", + "limitations under the License." + ], + "nodes": [ + { + "line": 2, + "column": 1, + "problem": "VarDeclaration", + "autofixable": false, + "suggest": "", + "rule": "Use \"let\" instead of \"var\" (arkts-no-var)" + }, + { + "line": 2, + "column": 9, + "problem": "ObjectLiteralNoContextType", + "autofixable": false, + "suggest": "", + "rule": "Object literal must correspond to some explicitly declared class or interface (arkts-no-untyped-obj-literals)" + }, + { + "line": 2, + "column": 10, + "problem": "LiteralAsPropertyName", + "autofixable": true, + "suggest": "", + "rule": "Objects with property names that are not identifiers are not supported (arkts-identifiers-as-prop-names)" + }, + { + "line": 2, + "column": 21, + "problem": "LiteralAsPropertyName", + "autofixable": true, + "suggest": "", + "rule": "Objects with property names that are not identifiers are not supported (arkts-identifiers-as-prop-names)" + }, + { + "line": 4, + "column": 13, + "problem": "PropertyAccessByIndex", + "autofixable": true, + "suggest": "", + "rule": "Indexed access is not supported for fields (arkts-no-props-by-index)" + }, + { + "line": 5, + "column": 13, + "problem": "PropertyAccessByIndex", + "autofixable": true, + "suggest": "", + "rule": "Indexed access is not supported for fields (arkts-no-props-by-index)" + }, + { + "line": 10, + "column": 9, + "problem": "ObjectLiteralNoContextType", + "autofixable": false, + "suggest": "", + "rule": "Object literal must correspond to some explicitly declared class or interface (arkts-no-untyped-obj-literals)" + }, + { + "line": 14, + "column": 13, + "problem": "PropertyAccessByIndex", + "autofixable": true, + "suggest": "", + "rule": "Indexed access is not supported for fields (arkts-no-props-by-index)" + } + ] +} \ No newline at end of file diff --git a/linter-4.2/test_rules/rule1.ts.relax.json b/linter-4.2/test_rules/rule1.ts.relax.json new file mode 100644 index 000000000..861e06d09 --- /dev/null +++ b/linter-4.2/test_rules/rule1.ts.relax.json @@ -0,0 +1,18 @@ +{ + "nodes": [ + { + "line": 2, + "column": 9, + "problem": "ObjectLiteralNoContextType", + "suggest": "", + "rule": "Object literal must correspond to some explicitly declared class or interface (arkts-no-untyped-obj-literals)" + }, + { + "line": 10, + "column": 9, + "problem": "ObjectLiteralNoContextType", + "suggest": "", + "rule": "Object literal must correspond to some explicitly declared class or interface (arkts-no-untyped-obj-literals)" + } + ] +} \ No newline at end of file diff --git a/linter-4.2/test_rules/rule1.ts.strict.json b/linter-4.2/test_rules/rule1.ts.strict.json new file mode 100644 index 000000000..5728ad6cd --- /dev/null +++ b/linter-4.2/test_rules/rule1.ts.strict.json @@ -0,0 +1,60 @@ +{ + "nodes": [ + { + "line": 2, + "column": 1, + "problem": "VarDeclaration", + "suggest": "", + "rule": "Use \"let\" instead of \"var\" (arkts-no-var)" + }, + { + "line": 2, + "column": 9, + "problem": "ObjectLiteralNoContextType", + "suggest": "", + "rule": "Object literal must correspond to some explicitly declared class or interface (arkts-no-untyped-obj-literals)" + }, + { + "line": 2, + "column": 10, + "problem": "LiteralAsPropertyName", + "suggest": "", + "rule": "Objects with property names that are not identifiers are not supported (arkts-identifiers-as-prop-names)" + }, + { + "line": 2, + "column": 21, + "problem": "LiteralAsPropertyName", + "suggest": "", + "rule": "Objects with property names that are not identifiers are not supported (arkts-identifiers-as-prop-names)" + }, + { + "line": 4, + "column": 13, + "problem": "PropertyAccessByIndex", + "suggest": "", + "rule": "Indexed access is not supported for fields (arkts-no-props-by-index)" + }, + { + "line": 5, + "column": 13, + "problem": "PropertyAccessByIndex", + "suggest": "", + "rule": "Indexed access is not supported for fields (arkts-no-props-by-index)" + }, + { + "line": 10, + "column": 9, + "problem": "ObjectLiteralNoContextType", + "suggest": "", + "rule": "Object literal must correspond to some explicitly declared class or interface (arkts-no-untyped-obj-literals)" + }, + { + "line": 14, + "column": 13, + "problem": "PropertyAccessByIndex", + "suggest": "", + "rule": "Indexed access is not supported for fields (arkts-no-props-by-index)" + } + ] +} \ No newline at end of file diff --git a/linter-4.2/test_rules/rule102.ts b/linter-4.2/test_rules/rule102.ts new file mode 100644 index 000000000..adf6f4ed1 --- /dev/null +++ b/linter-4.2/test_rules/rule102.ts @@ -0,0 +1,76 @@ +interface Mover { + getStatus(): { speed: number } +} +interface Shaker { + getStatus(): { frequency: number } +} + +interface MoverShaker extends Mover, Shaker { + getStatus(): { + speed: number + frequency: number + } +} + +class C implements MoverShaker { + private speed: number = 0 + private frequency: number = 0 + + getStatus() { + return { speed: this.speed, frequency: this.frequency } + } +} + +class MoveStatus { + public speed : number + constructor() { + this.speed = 0 + } +} +interface Mover { + getMoveStatus(): MoveStatus +} + +class ShakeStatus { + public frequency : number + constructor() { + this.frequency = 0 + } +} +interface Shaker { + getShakeStatus(): ShakeStatus +} + +class MoveAndShakeStatus { + public speed : number + public frequency : number + constructor() { + this.speed = 0 + this.frequency = 0 + } +} + +class D implements Mover, Shaker { + private move_status : MoveStatus + private shake_status : ShakeStatus + + constructor() { + this.move_status = new MoveStatus() + this.shake_status = new ShakeStatus() + } + + public getMoveStatus() : MoveStatus { + return this.move_status + } + + public getShakeStatus() : ShakeStatus { + return this.shake_status + } + + public getStatus(): MoveAndShakeStatus { + return { + speed: this.move_status.speed, + frequency: this.shake_status.frequency + } + } +} \ No newline at end of file diff --git a/linter-4.2/test_rules/rule102.ts.autofix.json b/linter-4.2/test_rules/rule102.ts.autofix.json new file mode 100644 index 000000000..e9faca40d --- /dev/null +++ b/linter-4.2/test_rules/rule102.ts.autofix.json @@ -0,0 +1,90 @@ +{ + "copyright": [ + "Copyright (c) 2023-2023 Huawei Device Co., Ltd.", + "Licensed under the Apache License, Version 2.0 (the 'License');", + "you may not use this file except in compliance with the License.", + "You may obtain a copy of the License at", + "", + "http://www.apache.org/licenses/LICENSE-2.0", + "", + "Unless required by applicable law or agreed to in writing, software", + "distributed under the License is distributed on an 'AS IS' BASIS,", + "WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.", + "See the License for the specific language governing permissions and", + "limitations under the License." + ], + "nodes": [ + { + "line": 1, + "column": 1, + "problem": "InterfaceMerging", + "autofixable": false, + "suggest": "", + "rule": "Declaration merging is not supported (arkts-no-decl-merging)" + }, + { + "line": 2, + "column": 18, + "problem": "ObjectTypeLiteral", + "autofixable": false, + "suggest": "", + "rule": "Object literals cannot be used as type declarations (arkts-no-obj-literals-as-types)" + }, + { + "line": 4, + "column": 1, + "problem": "InterfaceMerging", + "autofixable": false, + "suggest": "", + "rule": "Declaration merging is not supported (arkts-no-decl-merging)" + }, + { + "line": 5, + "column": 18, + "problem": "ObjectTypeLiteral", + "autofixable": false, + "suggest": "", + "rule": "Object literals cannot be used as type declarations (arkts-no-obj-literals-as-types)" + }, + { + "line": 8, + "column": 1, + "problem": "IntefaceExtendDifProps", + "autofixable": false, + "suggest": "", + "rule": "Interface can not extend interfaces with the same method (arkts-no-extend-same-prop)" + }, + { + "line": 9, + "column": 18, + "problem": "ObjectTypeLiteral", + "autofixable": false, + "suggest": "", + "rule": "Object literals cannot be used as type declarations (arkts-no-obj-literals-as-types)" + }, + { + "line": 20, + "column": 16, + "problem": "ObjectLiteralNoContextType", + "autofixable": false, + "suggest": "", + "rule": "Object literal must correspond to some explicitly declared class or interface (arkts-no-untyped-obj-literals)" + }, + { + "line": 30, + "column": 1, + "problem": "InterfaceMerging", + "autofixable": false, + "suggest": "", + "rule": "Declaration merging is not supported (arkts-no-decl-merging)" + }, + { + "line": 40, + "column": 1, + "problem": "InterfaceMerging", + "autofixable": false, + "suggest": "", + "rule": "Declaration merging is not supported (arkts-no-decl-merging)" + } + ] +} \ No newline at end of file diff --git a/linter-4.2/test_rules/rule102.ts.relax.json b/linter-4.2/test_rules/rule102.ts.relax.json new file mode 100644 index 000000000..40159bc31 --- /dev/null +++ b/linter-4.2/test_rules/rule102.ts.relax.json @@ -0,0 +1,81 @@ +{ + "copyright": [ + "Copyright (c) 2023-2023 Huawei Device Co., Ltd.", + "Licensed under the Apache License, Version 2.0 (the 'License');", + "you may not use this file except in compliance with the License.", + "You may obtain a copy of the License at", + "", + "http://www.apache.org/licenses/LICENSE-2.0", + "", + "Unless required by applicable law or agreed to in writing, software", + "distributed under the License is distributed on an 'AS IS' BASIS,", + "WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.", + "See the License for the specific language governing permissions and", + "limitations under the License." + ], + "nodes": [ + { + "line": 1, + "column": 1, + "problem": "InterfaceMerging", + "suggest": "", + "rule": "Declaration merging is not supported (arkts-no-decl-merging)" + }, + { + "line": 2, + "column": 18, + "problem": "ObjectTypeLiteral", + "suggest": "", + "rule": "Object literals cannot be used as type declarations (arkts-no-obj-literals-as-types)" + }, + { + "line": 4, + "column": 1, + "problem": "InterfaceMerging", + "suggest": "", + "rule": "Declaration merging is not supported (arkts-no-decl-merging)" + }, + { + "line": 5, + "column": 18, + "problem": "ObjectTypeLiteral", + "suggest": "", + "rule": "Object literals cannot be used as type declarations (arkts-no-obj-literals-as-types)" + }, + { + "line": 8, + "column": 1, + "problem": "IntefaceExtendDifProps", + "suggest": "", + "rule": "Interface can not extend interfaces with the same method (arkts-no-extend-same-prop)" + }, + { + "line": 9, + "column": 18, + "problem": "ObjectTypeLiteral", + "suggest": "", + "rule": "Object literals cannot be used as type declarations (arkts-no-obj-literals-as-types)" + }, + { + "line": 20, + "column": 16, + "problem": "ObjectLiteralNoContextType", + "suggest": "", + "rule": "Object literal must correspond to some explicitly declared class or interface (arkts-no-untyped-obj-literals)" + }, + { + "line": 30, + "column": 1, + "problem": "InterfaceMerging", + "suggest": "", + "rule": "Declaration merging is not supported (arkts-no-decl-merging)" + }, + { + "line": 40, + "column": 1, + "problem": "InterfaceMerging", + "suggest": "", + "rule": "Declaration merging is not supported (arkts-no-decl-merging)" + } + ] +} \ No newline at end of file diff --git a/linter-4.2/test_rules/rule102.ts.strict.json b/linter-4.2/test_rules/rule102.ts.strict.json new file mode 100644 index 000000000..40159bc31 --- /dev/null +++ b/linter-4.2/test_rules/rule102.ts.strict.json @@ -0,0 +1,81 @@ +{ + "copyright": [ + "Copyright (c) 2023-2023 Huawei Device Co., Ltd.", + "Licensed under the Apache License, Version 2.0 (the 'License');", + "you may not use this file except in compliance with the License.", + "You may obtain a copy of the License at", + "", + "http://www.apache.org/licenses/LICENSE-2.0", + "", + "Unless required by applicable law or agreed to in writing, software", + "distributed under the License is distributed on an 'AS IS' BASIS,", + "WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.", + "See the License for the specific language governing permissions and", + "limitations under the License." + ], + "nodes": [ + { + "line": 1, + "column": 1, + "problem": "InterfaceMerging", + "suggest": "", + "rule": "Declaration merging is not supported (arkts-no-decl-merging)" + }, + { + "line": 2, + "column": 18, + "problem": "ObjectTypeLiteral", + "suggest": "", + "rule": "Object literals cannot be used as type declarations (arkts-no-obj-literals-as-types)" + }, + { + "line": 4, + "column": 1, + "problem": "InterfaceMerging", + "suggest": "", + "rule": "Declaration merging is not supported (arkts-no-decl-merging)" + }, + { + "line": 5, + "column": 18, + "problem": "ObjectTypeLiteral", + "suggest": "", + "rule": "Object literals cannot be used as type declarations (arkts-no-obj-literals-as-types)" + }, + { + "line": 8, + "column": 1, + "problem": "IntefaceExtendDifProps", + "suggest": "", + "rule": "Interface can not extend interfaces with the same method (arkts-no-extend-same-prop)" + }, + { + "line": 9, + "column": 18, + "problem": "ObjectTypeLiteral", + "suggest": "", + "rule": "Object literals cannot be used as type declarations (arkts-no-obj-literals-as-types)" + }, + { + "line": 20, + "column": 16, + "problem": "ObjectLiteralNoContextType", + "suggest": "", + "rule": "Object literal must correspond to some explicitly declared class or interface (arkts-no-untyped-obj-literals)" + }, + { + "line": 30, + "column": 1, + "problem": "InterfaceMerging", + "suggest": "", + "rule": "Declaration merging is not supported (arkts-no-decl-merging)" + }, + { + "line": 40, + "column": 1, + "problem": "InterfaceMerging", + "suggest": "", + "rule": "Declaration merging is not supported (arkts-no-decl-merging)" + } + ] +} \ No newline at end of file diff --git a/linter-4.2/test_rules/rule103.ts b/linter-4.2/test_rules/rule103.ts new file mode 100644 index 000000000..19124189a --- /dev/null +++ b/linter-4.2/test_rules/rule103.ts @@ -0,0 +1,13 @@ +interface Document { + createElement(tagName: any): Element +} + +interface Document { + createElement(tagName: string): HTMLElement +} + +interface Document { + createElement(tagName: number): HTMLDivElement + createElement(tagName: boolean): HTMLSpanElement + createElement(tagName: string, value: number): HTMLCanvasElement +} \ No newline at end of file diff --git a/linter-4.2/test_rules/rule103.ts.autofix.json b/linter-4.2/test_rules/rule103.ts.autofix.json new file mode 100644 index 000000000..0b80e8ace --- /dev/null +++ b/linter-4.2/test_rules/rule103.ts.autofix.json @@ -0,0 +1,74 @@ +{ + "copyright": [ + "Copyright (c) 2023-2023 Huawei Device Co., Ltd.", + "Licensed under the Apache License, Version 2.0 (the 'License');", + "you may not use this file except in compliance with the License.", + "You may obtain a copy of the License at", + "", + "http://www.apache.org/licenses/LICENSE-2.0", + "", + "Unless required by applicable law or agreed to in writing, software", + "distributed under the License is distributed on an 'AS IS' BASIS,", + "WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.", + "See the License for the specific language governing permissions and", + "limitations under the License." + ], + "nodes": [ + { + "line": 1, + "column": 1, + "problem": "InterfaceMerging", + "autofixable": false, + "suggest": "", + "rule": "Declaration merging is not supported (arkts-no-decl-merging)" + }, + { + "line": 1, + "column": 1, + "problem": "DeclWithDuplicateName", + "autofixable": false, + "suggest": "", + "rule": "Use unique names for types and namespaces. (arkts-unique-names)" + }, + { + "line": 2, + "column": 28, + "problem": "AnyType", + "autofixable": false, + "suggest": "", + "rule": "Use explicit types instead of \"any\", \"unknown\" (arkts-no-any-unknown)" + }, + { + "line": 5, + "column": 1, + "problem": "InterfaceMerging", + "autofixable": false, + "suggest": "", + "rule": "Declaration merging is not supported (arkts-no-decl-merging)" + }, + { + "line": 5, + "column": 1, + "problem": "DeclWithDuplicateName", + "autofixable": false, + "suggest": "", + "rule": "Use unique names for types and namespaces. (arkts-unique-names)" + }, + { + "line": 9, + "column": 1, + "problem": "InterfaceMerging", + "autofixable": false, + "suggest": "", + "rule": "Declaration merging is not supported (arkts-no-decl-merging)" + }, + { + "line": 9, + "column": 1, + "problem": "DeclWithDuplicateName", + "autofixable": false, + "suggest": "", + "rule": "Use unique names for types and namespaces. (arkts-unique-names)" + } + ] +} \ No newline at end of file diff --git a/linter-4.2/test_rules/rule103.ts.relax.json b/linter-4.2/test_rules/rule103.ts.relax.json new file mode 100644 index 000000000..cf7d4c009 --- /dev/null +++ b/linter-4.2/test_rules/rule103.ts.relax.json @@ -0,0 +1,32 @@ +{ + "nodes": [ + { + "line": 1, + "column": 1, + "problem": "InterfaceMerging", + "suggest": "", + "rule": "Declaration merging is not supported (arkts-no-decl-merging)" + }, + { + "line": 2, + "column": 28, + "problem": "AnyType", + "suggest": "", + "rule": "Use explicit types instead of \"any\", \"unknown\" (arkts-no-any-unknown)" + }, + { + "line": 5, + "column": 1, + "problem": "InterfaceMerging", + "suggest": "", + "rule": "Declaration merging is not supported (arkts-no-decl-merging)" + }, + { + "line": 9, + "column": 1, + "problem": "InterfaceMerging", + "suggest": "", + "rule": "Declaration merging is not supported (arkts-no-decl-merging)" + } + ] +} \ No newline at end of file diff --git a/linter-4.2/test_rules/rule103.ts.strict.json b/linter-4.2/test_rules/rule103.ts.strict.json new file mode 100644 index 000000000..ed74f56a2 --- /dev/null +++ b/linter-4.2/test_rules/rule103.ts.strict.json @@ -0,0 +1,67 @@ +{ + "copyright": [ + "Copyright (c) 2023-2023 Huawei Device Co., Ltd.", + "Licensed under the Apache License, Version 2.0 (the 'License');", + "you may not use this file except in compliance with the License.", + "You may obtain a copy of the License at", + "", + "http://www.apache.org/licenses/LICENSE-2.0", + "", + "Unless required by applicable law or agreed to in writing, software", + "distributed under the License is distributed on an 'AS IS' BASIS,", + "WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.", + "See the License for the specific language governing permissions and", + "limitations under the License." + ], + "nodes": [ + { + "line": 1, + "column": 1, + "problem": "InterfaceMerging", + "suggest": "", + "rule": "Declaration merging is not supported (arkts-no-decl-merging)" + }, + { + "line": 1, + "column": 1, + "problem": "DeclWithDuplicateName", + "suggest": "", + "rule": "Use unique names for types and namespaces. (arkts-unique-names)" + }, + { + "line": 2, + "column": 28, + "problem": "AnyType", + "suggest": "", + "rule": "Use explicit types instead of \"any\", \"unknown\" (arkts-no-any-unknown)" + }, + { + "line": 5, + "column": 1, + "problem": "InterfaceMerging", + "suggest": "", + "rule": "Declaration merging is not supported (arkts-no-decl-merging)" + }, + { + "line": 5, + "column": 1, + "problem": "DeclWithDuplicateName", + "suggest": "", + "rule": "Use unique names for types and namespaces. (arkts-unique-names)" + }, + { + "line": 9, + "column": 1, + "problem": "InterfaceMerging", + "suggest": "", + "rule": "Declaration merging is not supported (arkts-no-decl-merging)" + }, + { + "line": 9, + "column": 1, + "problem": "DeclWithDuplicateName", + "suggest": "", + "rule": "Use unique names for types and namespaces. (arkts-unique-names)" + } + ] +} \ No newline at end of file diff --git a/linter-4.2/test_rules/rule104.ts b/linter-4.2/test_rules/rule104.ts new file mode 100644 index 000000000..65df1e4e2 --- /dev/null +++ b/linter-4.2/test_rules/rule104.ts @@ -0,0 +1,7 @@ +class Control { + state: number = 0 +} + +interface SelectableControl extends Control { + select(): void +} \ No newline at end of file diff --git a/linter-4.2/test_rules/rule104.ts.autofix.json b/linter-4.2/test_rules/rule104.ts.autofix.json new file mode 100644 index 000000000..72f785ae1 --- /dev/null +++ b/linter-4.2/test_rules/rule104.ts.autofix.json @@ -0,0 +1,12 @@ +{ + "nodes": [ + { + "line": 5, + "column": 1, + "problem": "InterfaceExtendsClass", + "autofixable": false, + "suggest": "", + "rule": "Interfaces cannot extend classes (arkts-extends-only-class)" + } + ] +} \ No newline at end of file diff --git a/linter-4.2/test_rules/rule104.ts.relax.json b/linter-4.2/test_rules/rule104.ts.relax.json new file mode 100644 index 000000000..7b41949d1 --- /dev/null +++ b/linter-4.2/test_rules/rule104.ts.relax.json @@ -0,0 +1,11 @@ +{ + "nodes": [ + { + "line": 5, + "column": 1, + "problem": "InterfaceExtendsClass", + "suggest": "", + "rule": "Interfaces cannot extend classes (arkts-extends-only-class)" + } + ] +} \ No newline at end of file diff --git a/linter-4.2/test_rules/rule104.ts.strict.json b/linter-4.2/test_rules/rule104.ts.strict.json new file mode 100644 index 000000000..7b41949d1 --- /dev/null +++ b/linter-4.2/test_rules/rule104.ts.strict.json @@ -0,0 +1,11 @@ +{ + "nodes": [ + { + "line": 5, + "column": 1, + "problem": "InterfaceExtendsClass", + "suggest": "", + "rule": "Interfaces cannot extend classes (arkts-extends-only-class)" + } + ] +} \ No newline at end of file diff --git a/linter-4.2/test_rules/rule105.ts b/linter-4.2/test_rules/rule105.ts new file mode 100644 index 000000000..6bb74d05e --- /dev/null +++ b/linter-4.2/test_rules/rule105.ts @@ -0,0 +1,15 @@ +class A { + foo() {} + bar() {} +} + +function getSomeObject() { + return new A() +} + +let obj: any = getSomeObject() +if (obj && obj.foo && obj.bar) { + console.log("Yes") // prints "Yes" in this example +} else { + console.log("No") +} \ No newline at end of file diff --git a/linter-4.2/test_rules/rule105.ts.autofix.json b/linter-4.2/test_rules/rule105.ts.autofix.json new file mode 100644 index 000000000..dec758fff --- /dev/null +++ b/linter-4.2/test_rules/rule105.ts.autofix.json @@ -0,0 +1,28 @@ +{ + "nodes": [ + { + "line": 10, + "column": 10, + "problem": "AnyType", + "autofixable": false, + "suggest": "", + "rule": "Use explicit types instead of \"any\", \"unknown\" (arkts-no-any-unknown)" + }, + { + "line": 11, + "column": 12, + "problem": "PropertyRuntimeCheck", + "autofixable": false, + "suggest": "", + "rule": "Property-based runtime type checks are not supported (arkts-no-prop-existence-check)" + }, + { + "line": 11, + "column": 23, + "problem": "PropertyRuntimeCheck", + "autofixable": false, + "suggest": "", + "rule": "Property-based runtime type checks are not supported (arkts-no-prop-existence-check)" + } + ] +} \ No newline at end of file diff --git a/linter-4.2/test_rules/rule105.ts.relax.json b/linter-4.2/test_rules/rule105.ts.relax.json new file mode 100644 index 000000000..ea58d6f20 --- /dev/null +++ b/linter-4.2/test_rules/rule105.ts.relax.json @@ -0,0 +1,25 @@ +{ + "nodes": [ + { + "line": 10, + "column": 10, + "problem": "AnyType", + "suggest": "", + "rule": "Use explicit types instead of \"any\", \"unknown\" (arkts-no-any-unknown)" + }, + { + "line": 11, + "column": 12, + "problem": "PropertyRuntimeCheck", + "suggest": "", + "rule": "Property-based runtime type checks are not supported (arkts-no-prop-existence-check)" + }, + { + "line": 11, + "column": 23, + "problem": "PropertyRuntimeCheck", + "suggest": "", + "rule": "Property-based runtime type checks are not supported (arkts-no-prop-existence-check)" + } + ] +} \ No newline at end of file diff --git a/linter-4.2/test_rules/rule105.ts.strict.json b/linter-4.2/test_rules/rule105.ts.strict.json new file mode 100644 index 000000000..ea58d6f20 --- /dev/null +++ b/linter-4.2/test_rules/rule105.ts.strict.json @@ -0,0 +1,25 @@ +{ + "nodes": [ + { + "line": 10, + "column": 10, + "problem": "AnyType", + "suggest": "", + "rule": "Use explicit types instead of \"any\", \"unknown\" (arkts-no-any-unknown)" + }, + { + "line": 11, + "column": 12, + "problem": "PropertyRuntimeCheck", + "suggest": "", + "rule": "Property-based runtime type checks are not supported (arkts-no-prop-existence-check)" + }, + { + "line": 11, + "column": 23, + "problem": "PropertyRuntimeCheck", + "suggest": "", + "rule": "Property-based runtime type checks are not supported (arkts-no-prop-existence-check)" + } + ] +} \ No newline at end of file diff --git a/linter-4.2/test_rules/rule106.ts b/linter-4.2/test_rules/rule106.ts new file mode 100644 index 000000000..1ab230279 --- /dev/null +++ b/linter-4.2/test_rules/rule106.ts @@ -0,0 +1,14 @@ +class Person { + constructor( + name: string, + age: number + ) {} +} +type PersonCtor = new (name: string, age: number) => Person + +function createPerson(Ctor: PersonCtor, name: string, age: number): Person +{ + return new Ctor(name, age) +} + +const person = createPerson(Person, 'John', 30) \ No newline at end of file diff --git a/linter-4.2/test_rules/rule106.ts.autofix.json b/linter-4.2/test_rules/rule106.ts.autofix.json new file mode 100644 index 000000000..c9ee8bc8e --- /dev/null +++ b/linter-4.2/test_rules/rule106.ts.autofix.json @@ -0,0 +1,34 @@ +{ + "copyright": [ + "Copyright (c) 2023-2023 Huawei Device Co., Ltd.", + "Licensed under the Apache License, Version 2.0 (the 'License');", + "you may not use this file except in compliance with the License.", + "You may obtain a copy of the License at", + "", + "http://www.apache.org/licenses/LICENSE-2.0", + "", + "Unless required by applicable law or agreed to in writing, software", + "distributed under the License is distributed on an 'AS IS' BASIS,", + "WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.", + "See the License for the specific language governing permissions and", + "limitations under the License." + ], + "nodes": [ + { + "line": 7, + "column": 19, + "problem": "ConstructorFuncs", + "autofixable": false, + "suggest": "", + "rule": "Constructor function type is not supported (arkts-no-ctor-signatures-funcs)" + }, + { + "line": 14, + "column": 29, + "problem": "ClassAsObject", + "autofixable": false, + "suggest": "", + "rule": "Classes cannot be used as objects (arkts-no-classes-as-obj)" + } + ] +} \ No newline at end of file diff --git a/linter-4.2/test_rules/rule106.ts.relax.json b/linter-4.2/test_rules/rule106.ts.relax.json new file mode 100644 index 000000000..9af8cdfaa --- /dev/null +++ b/linter-4.2/test_rules/rule106.ts.relax.json @@ -0,0 +1,32 @@ +{ + "copyright": [ + "Copyright (c) 2023-2023 Huawei Device Co., Ltd.", + "Licensed under the Apache License, Version 2.0 (the 'License');", + "you may not use this file except in compliance with the License.", + "You may obtain a copy of the License at", + "", + "http://www.apache.org/licenses/LICENSE-2.0", + "", + "Unless required by applicable law or agreed to in writing, software", + "distributed under the License is distributed on an 'AS IS' BASIS,", + "WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.", + "See the License for the specific language governing permissions and", + "limitations under the License." + ], + "nodes": [ + { + "line": 7, + "column": 19, + "problem": "ConstructorFuncs", + "suggest": "", + "rule": "Constructor function type is not supported (arkts-no-ctor-signatures-funcs)" + }, + { + "line": 14, + "column": 29, + "problem": "ClassAsObject", + "suggest": "", + "rule": "Classes cannot be used as objects (arkts-no-classes-as-obj)" + } + ] +} \ No newline at end of file diff --git a/linter-4.2/test_rules/rule106.ts.strict.json b/linter-4.2/test_rules/rule106.ts.strict.json new file mode 100644 index 000000000..9af8cdfaa --- /dev/null +++ b/linter-4.2/test_rules/rule106.ts.strict.json @@ -0,0 +1,32 @@ +{ + "copyright": [ + "Copyright (c) 2023-2023 Huawei Device Co., Ltd.", + "Licensed under the Apache License, Version 2.0 (the 'License');", + "you may not use this file except in compliance with the License.", + "You may obtain a copy of the License at", + "", + "http://www.apache.org/licenses/LICENSE-2.0", + "", + "Unless required by applicable law or agreed to in writing, software", + "distributed under the License is distributed on an 'AS IS' BASIS,", + "WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.", + "See the License for the specific language governing permissions and", + "limitations under the License." + ], + "nodes": [ + { + "line": 7, + "column": 19, + "problem": "ConstructorFuncs", + "suggest": "", + "rule": "Constructor function type is not supported (arkts-no-ctor-signatures-funcs)" + }, + { + "line": 14, + "column": 29, + "problem": "ClassAsObject", + "suggest": "", + "rule": "Classes cannot be used as objects (arkts-no-classes-as-obj)" + } + ] +} \ No newline at end of file diff --git a/linter-4.2/test_rules/rule109.ts b/linter-4.2/test_rules/rule109.ts new file mode 100644 index 000000000..f059bcfd6 --- /dev/null +++ b/linter-4.2/test_rules/rule109.ts @@ -0,0 +1,12 @@ +class Person { + name: string = "" + age: number = 0; // semicolon is required here + [key: string]: string | number +} + +const person: Person = { + name: "John", + age: 30, + email: "john@example.com", + phone: 1234567890, +} \ No newline at end of file diff --git a/linter-4.2/test_rules/rule109.ts.autofix.json b/linter-4.2/test_rules/rule109.ts.autofix.json new file mode 100644 index 000000000..0b6dbe558 --- /dev/null +++ b/linter-4.2/test_rules/rule109.ts.autofix.json @@ -0,0 +1,20 @@ +{ + "nodes": [ + { + "line": 4, + "column": 5, + "problem": "IndexMember", + "autofixable": false, + "suggest": "", + "rule": "Indexed signatures are not supported (arkts-no-indexed-signatures)" + }, + { + "line": 7, + "column": 24, + "problem": "ObjectLiteralNoContextType", + "autofixable": false, + "suggest": "", + "rule": "Object literal must correspond to some explicitly declared class or interface (arkts-no-untyped-obj-literals)" + } + ] +} \ No newline at end of file diff --git a/linter-4.2/test_rules/rule109.ts.relax.json b/linter-4.2/test_rules/rule109.ts.relax.json new file mode 100644 index 000000000..4e3cec02b --- /dev/null +++ b/linter-4.2/test_rules/rule109.ts.relax.json @@ -0,0 +1,18 @@ +{ + "nodes": [ + { + "line": 4, + "column": 5, + "problem": "IndexMember", + "suggest": "", + "rule": "Indexed signatures are not supported (arkts-no-indexed-signatures)" + }, + { + "line": 7, + "column": 24, + "problem": "ObjectLiteralNoContextType", + "suggest": "", + "rule": "Object literal must correspond to some explicitly declared class or interface (arkts-no-untyped-obj-literals)" + } + ] +} \ No newline at end of file diff --git a/linter-4.2/test_rules/rule109.ts.strict.json b/linter-4.2/test_rules/rule109.ts.strict.json new file mode 100644 index 000000000..4e3cec02b --- /dev/null +++ b/linter-4.2/test_rules/rule109.ts.strict.json @@ -0,0 +1,18 @@ +{ + "nodes": [ + { + "line": 4, + "column": 5, + "problem": "IndexMember", + "suggest": "", + "rule": "Indexed signatures are not supported (arkts-no-indexed-signatures)" + }, + { + "line": 7, + "column": 24, + "problem": "ObjectLiteralNoContextType", + "suggest": "", + "rule": "Object literal must correspond to some explicitly declared class or interface (arkts-no-untyped-obj-literals)" + } + ] +} \ No newline at end of file diff --git a/linter-4.2/test_rules/rule111.ts b/linter-4.2/test_rules/rule111.ts new file mode 100644 index 000000000..03f37395d --- /dev/null +++ b/linter-4.2/test_rules/rule111.ts @@ -0,0 +1,14 @@ +enum E1 { + A = 0xa, + B = 0xb, + C = Math.random(), + D = 0xd, + E // 0xe inferred +} + +enum E2 { + A = 0xa, + B = "0xb", + C = 0xc, + D = "0xd" +} \ No newline at end of file diff --git a/linter-4.2/test_rules/rule111.ts.autofix.json b/linter-4.2/test_rules/rule111.ts.autofix.json new file mode 100644 index 000000000..ac5927342 --- /dev/null +++ b/linter-4.2/test_rules/rule111.ts.autofix.json @@ -0,0 +1,28 @@ +{ + "nodes": [ + { + "line": 4, + "column": 5, + "problem": "EnumMemberNonConstInit", + "autofixable": false, + "suggest": "", + "rule": "Enumeration members can be initialized only with compile time expressions of the same type (arkts-no-enum-mixed-types)" + }, + { + "line": 11, + "column": 5, + "problem": "EnumMemberNonConstInit", + "autofixable": false, + "suggest": "", + "rule": "Enumeration members can be initialized only with compile time expressions of the same type (arkts-no-enum-mixed-types)" + }, + { + "line": 13, + "column": 5, + "problem": "EnumMemberNonConstInit", + "autofixable": false, + "suggest": "", + "rule": "Enumeration members can be initialized only with compile time expressions of the same type (arkts-no-enum-mixed-types)" + } + ] +} \ No newline at end of file diff --git a/linter-4.2/test_rules/rule111.ts.relax.json b/linter-4.2/test_rules/rule111.ts.relax.json new file mode 100644 index 000000000..38d991289 --- /dev/null +++ b/linter-4.2/test_rules/rule111.ts.relax.json @@ -0,0 +1,25 @@ +{ + "nodes": [ + { + "line": 4, + "column": 5, + "problem": "EnumMemberNonConstInit", + "suggest": "", + "rule": "Enumeration members can be initialized only with compile time expressions of the same type (arkts-no-enum-mixed-types)" + }, + { + "line": 11, + "column": 5, + "problem": "EnumMemberNonConstInit", + "suggest": "", + "rule": "Enumeration members can be initialized only with compile time expressions of the same type (arkts-no-enum-mixed-types)" + }, + { + "line": 13, + "column": 5, + "problem": "EnumMemberNonConstInit", + "suggest": "", + "rule": "Enumeration members can be initialized only with compile time expressions of the same type (arkts-no-enum-mixed-types)" + } + ] +} \ No newline at end of file diff --git a/linter-4.2/test_rules/rule111.ts.strict.json b/linter-4.2/test_rules/rule111.ts.strict.json new file mode 100644 index 000000000..38d991289 --- /dev/null +++ b/linter-4.2/test_rules/rule111.ts.strict.json @@ -0,0 +1,25 @@ +{ + "nodes": [ + { + "line": 4, + "column": 5, + "problem": "EnumMemberNonConstInit", + "suggest": "", + "rule": "Enumeration members can be initialized only with compile time expressions of the same type (arkts-no-enum-mixed-types)" + }, + { + "line": 11, + "column": 5, + "problem": "EnumMemberNonConstInit", + "suggest": "", + "rule": "Enumeration members can be initialized only with compile time expressions of the same type (arkts-no-enum-mixed-types)" + }, + { + "line": 13, + "column": 5, + "problem": "EnumMemberNonConstInit", + "suggest": "", + "rule": "Enumeration members can be initialized only with compile time expressions of the same type (arkts-no-enum-mixed-types)" + } + ] +} \ No newline at end of file diff --git a/linter-4.2/test_rules/rule113.ts b/linter-4.2/test_rules/rule113.ts new file mode 100644 index 000000000..d6880ec87 --- /dev/null +++ b/linter-4.2/test_rules/rule113.ts @@ -0,0 +1,11 @@ +enum Color { + RED, + GREEN +} +enum Color { + YELLOW = 2 +} +enum Color { + BLACK = 3, + BLUE +} \ No newline at end of file diff --git a/linter-4.2/test_rules/rule113.ts.autofix.json b/linter-4.2/test_rules/rule113.ts.autofix.json new file mode 100644 index 000000000..58f9d799d --- /dev/null +++ b/linter-4.2/test_rules/rule113.ts.autofix.json @@ -0,0 +1,28 @@ +{ + "nodes": [ + { + "line": 1, + "column": 1, + "problem": "EnumMerging", + "autofixable": false, + "suggest": "", + "rule": "\"enum\" declaration merging is not supported (arkts-no-enum-merging)" + }, + { + "line": 5, + "column": 1, + "problem": "EnumMerging", + "autofixable": false, + "suggest": "", + "rule": "\"enum\" declaration merging is not supported (arkts-no-enum-merging)" + }, + { + "line": 8, + "column": 1, + "problem": "EnumMerging", + "autofixable": false, + "suggest": "", + "rule": "\"enum\" declaration merging is not supported (arkts-no-enum-merging)" + } + ] +} \ No newline at end of file diff --git a/linter-4.2/test_rules/rule113.ts.relax.json b/linter-4.2/test_rules/rule113.ts.relax.json new file mode 100644 index 000000000..b6613b855 --- /dev/null +++ b/linter-4.2/test_rules/rule113.ts.relax.json @@ -0,0 +1,25 @@ +{ + "nodes": [ + { + "line": 1, + "column": 1, + "problem": "EnumMerging", + "suggest": "", + "rule": "\"enum\" declaration merging is not supported (arkts-no-enum-merging)" + }, + { + "line": 5, + "column": 1, + "problem": "EnumMerging", + "suggest": "", + "rule": "\"enum\" declaration merging is not supported (arkts-no-enum-merging)" + }, + { + "line": 8, + "column": 1, + "problem": "EnumMerging", + "suggest": "", + "rule": "\"enum\" declaration merging is not supported (arkts-no-enum-merging)" + } + ] +} \ No newline at end of file diff --git a/linter-4.2/test_rules/rule113.ts.strict.json b/linter-4.2/test_rules/rule113.ts.strict.json new file mode 100644 index 000000000..b6613b855 --- /dev/null +++ b/linter-4.2/test_rules/rule113.ts.strict.json @@ -0,0 +1,25 @@ +{ + "nodes": [ + { + "line": 1, + "column": 1, + "problem": "EnumMerging", + "suggest": "", + "rule": "\"enum\" declaration merging is not supported (arkts-no-enum-merging)" + }, + { + "line": 5, + "column": 1, + "problem": "EnumMerging", + "suggest": "", + "rule": "\"enum\" declaration merging is not supported (arkts-no-enum-merging)" + }, + { + "line": 8, + "column": 1, + "problem": "EnumMerging", + "suggest": "", + "rule": "\"enum\" declaration merging is not supported (arkts-no-enum-merging)" + } + ] +} \ No newline at end of file diff --git a/linter-4.2/test_rules/rule114.ts b/linter-4.2/test_rules/rule114.ts new file mode 100644 index 000000000..874568372 --- /dev/null +++ b/linter-4.2/test_rules/rule114.ts @@ -0,0 +1,6 @@ +namespace MyNamespace { + export let x: number +} + +let m = MyNamespace +m.x = 2 \ No newline at end of file diff --git a/linter-4.2/test_rules/rule114.ts.autofix.json b/linter-4.2/test_rules/rule114.ts.autofix.json new file mode 100644 index 000000000..c13bc7ded --- /dev/null +++ b/linter-4.2/test_rules/rule114.ts.autofix.json @@ -0,0 +1,12 @@ +{ + "nodes": [ + { + "line": 5, + "column": 9, + "problem": "NamespaceAsObject", + "autofixable": false, + "suggest": "", + "rule": "Namespaces cannot be used as objects (arkts-no-ns-as-obj)" + } + ] +} \ No newline at end of file diff --git a/linter-4.2/test_rules/rule114.ts.relax.json b/linter-4.2/test_rules/rule114.ts.relax.json new file mode 100644 index 000000000..1e0d3c333 --- /dev/null +++ b/linter-4.2/test_rules/rule114.ts.relax.json @@ -0,0 +1,11 @@ +{ + "nodes": [ + { + "line": 5, + "column": 9, + "problem": "NamespaceAsObject", + "suggest": "", + "rule": "Namespaces cannot be used as objects (arkts-no-ns-as-obj)" + } + ] +} \ No newline at end of file diff --git a/linter-4.2/test_rules/rule114.ts.strict.json b/linter-4.2/test_rules/rule114.ts.strict.json new file mode 100644 index 000000000..1e0d3c333 --- /dev/null +++ b/linter-4.2/test_rules/rule114.ts.strict.json @@ -0,0 +1,11 @@ +{ + "nodes": [ + { + "line": 5, + "column": 9, + "problem": "NamespaceAsObject", + "suggest": "", + "rule": "Namespaces cannot be used as objects (arkts-no-ns-as-obj)" + } + ] +} \ No newline at end of file diff --git a/linter-4.2/test_rules/rule116.ts b/linter-4.2/test_rules/rule116.ts new file mode 100644 index 000000000..be59f4075 --- /dev/null +++ b/linter-4.2/test_rules/rule116.ts @@ -0,0 +1,4 @@ +namespace A { + export let x: number + x = 1 +} \ No newline at end of file diff --git a/linter-4.2/test_rules/rule116.ts.autofix.json b/linter-4.2/test_rules/rule116.ts.autofix.json new file mode 100644 index 000000000..8449964f6 --- /dev/null +++ b/linter-4.2/test_rules/rule116.ts.autofix.json @@ -0,0 +1,12 @@ +{ + "nodes": [ + { + "line": 3, + "column": 5, + "problem": "NonDeclarationInNamespace", + "autofixable": false, + "suggest": "", + "rule": "Non-declaration statements in namespaces are not supported (arkts-no-ns-statements)" + } + ] +} \ No newline at end of file diff --git a/linter-4.2/test_rules/rule116.ts.relax.json b/linter-4.2/test_rules/rule116.ts.relax.json new file mode 100644 index 000000000..a5030d64e --- /dev/null +++ b/linter-4.2/test_rules/rule116.ts.relax.json @@ -0,0 +1,11 @@ +{ + "nodes": [ + { + "line": 3, + "column": 5, + "problem": "NonDeclarationInNamespace", + "suggest": "", + "rule": "Non-declaration statements in namespaces are not supported (arkts-no-ns-statements)" + } + ] +} \ No newline at end of file diff --git a/linter-4.2/test_rules/rule116.ts.strict.json b/linter-4.2/test_rules/rule116.ts.strict.json new file mode 100644 index 000000000..a5030d64e --- /dev/null +++ b/linter-4.2/test_rules/rule116.ts.strict.json @@ -0,0 +1,11 @@ +{ + "nodes": [ + { + "line": 3, + "column": 5, + "problem": "NonDeclarationInNamespace", + "suggest": "", + "rule": "Non-declaration statements in namespaces are not supported (arkts-no-ns-statements)" + } + ] +} \ No newline at end of file diff --git a/linter-4.2/test_rules/rule118.ts b/linter-4.2/test_rules/rule118.ts new file mode 100644 index 000000000..d8fcc327c --- /dev/null +++ b/linter-4.2/test_rules/rule118.ts @@ -0,0 +1,5 @@ + // Re-using the same import + import { APIResponseType } from "api" + + // Explicitly use import type + import type { APIResponseType } from "api" \ No newline at end of file diff --git a/linter-4.2/test_rules/rule118.ts.autofix.json b/linter-4.2/test_rules/rule118.ts.autofix.json new file mode 100644 index 000000000..3ff68f6c7 --- /dev/null +++ b/linter-4.2/test_rules/rule118.ts.autofix.json @@ -0,0 +1,19 @@ +{ + "nodes": [ + { + "line": 5, + "column": 12, + "problem": "TypeOnlyImport", + "autofixable": true, + "autofix": [ + { + "start": 120, + "end": 144, + "replacementText": "{ APIResponseType }" + } + ], + "suggest": "", + "rule": "Special import type declarations are not supported (arkts-no-special-imports)" + } + ] +} \ No newline at end of file diff --git a/linter-4.2/test_rules/rule118.ts.relax.json b/linter-4.2/test_rules/rule118.ts.relax.json new file mode 100644 index 000000000..13f13363f --- /dev/null +++ b/linter-4.2/test_rules/rule118.ts.relax.json @@ -0,0 +1,3 @@ +{ + "nodes": [] +} \ No newline at end of file diff --git a/linter-4.2/test_rules/rule118.ts.strict.json b/linter-4.2/test_rules/rule118.ts.strict.json new file mode 100644 index 000000000..d30836a74 --- /dev/null +++ b/linter-4.2/test_rules/rule118.ts.strict.json @@ -0,0 +1,11 @@ +{ + "nodes": [ + { + "line": 5, + "column": 12, + "problem": "TypeOnlyImport", + "suggest": "", + "rule": "Special import type declarations are not supported (arkts-no-special-imports)" + } + ] +} \ No newline at end of file diff --git a/linter-4.2/test_rules/rule119.ts b/linter-4.2/test_rules/rule119.ts new file mode 100644 index 000000000..6a34b0cab --- /dev/null +++ b/linter-4.2/test_rules/rule119.ts @@ -0,0 +1,9 @@ + + // === module at "path/to/module.ts" + export const EXAMPLE_VALUE = 42 + + // Set a global variable + window.MY_GLOBAL_VAR = "Hello, world!" + + // ==== using this module: + import "path/to/module" \ No newline at end of file diff --git a/linter-4.2/test_rules/rule119.ts.autofix.json b/linter-4.2/test_rules/rule119.ts.autofix.json new file mode 100644 index 000000000..a59a65d92 --- /dev/null +++ b/linter-4.2/test_rules/rule119.ts.autofix.json @@ -0,0 +1,19 @@ +{ + "nodes": [ + { + "line": 9, + "column": 5, + "problem": "ImportAfterStatement", + "autofixable": false, + "rule": "\"import\" statements after other statements are not allowed (arkts-no-misplaced-imports)" + }, + { + "line": 9, + "column": 5, + "problem": "ImportFromPath", + "autofixable": false, + "suggest": "", + "rule": "Importing a module for side-effects only is not supported (arkts-no-side-effects-imports)" + } + ] +} \ No newline at end of file diff --git a/linter-4.2/test_rules/rule119.ts.relax.json b/linter-4.2/test_rules/rule119.ts.relax.json new file mode 100644 index 000000000..a4d73e611 --- /dev/null +++ b/linter-4.2/test_rules/rule119.ts.relax.json @@ -0,0 +1,17 @@ +{ + "nodes": [ + { + "line": 9, + "column": 5, + "problem": "ImportAfterStatement", + "rule": "\"import\" statements after other statements are not allowed (arkts-no-misplaced-imports)" + }, + { + "line": 9, + "column": 5, + "problem": "ImportFromPath", + "suggest": "", + "rule": "Importing a module for side-effects only is not supported (arkts-no-side-effects-imports)" + } + ] +} \ No newline at end of file diff --git a/linter-4.2/test_rules/rule119.ts.strict.json b/linter-4.2/test_rules/rule119.ts.strict.json new file mode 100644 index 000000000..a4d73e611 --- /dev/null +++ b/linter-4.2/test_rules/rule119.ts.strict.json @@ -0,0 +1,17 @@ +{ + "nodes": [ + { + "line": 9, + "column": 5, + "problem": "ImportAfterStatement", + "rule": "\"import\" statements after other statements are not allowed (arkts-no-misplaced-imports)" + }, + { + "line": 9, + "column": 5, + "problem": "ImportFromPath", + "suggest": "", + "rule": "Importing a module for side-effects only is not supported (arkts-no-side-effects-imports)" + } + ] +} \ No newline at end of file diff --git a/linter-4.2/test_rules/rule120.ts b/linter-4.2/test_rules/rule120.ts new file mode 100644 index 000000000..708e6e63e --- /dev/null +++ b/linter-4.2/test_rules/rule120.ts @@ -0,0 +1 @@ +import { default as d } from "mod" \ No newline at end of file diff --git a/linter-4.2/test_rules/rule120.ts.autofix.json b/linter-4.2/test_rules/rule120.ts.autofix.json new file mode 100644 index 000000000..1b75d551f --- /dev/null +++ b/linter-4.2/test_rules/rule120.ts.autofix.json @@ -0,0 +1,19 @@ +{ + "nodes": [ + { + "line": 1, + "column": 10, + "problem": "DefaultImport", + "autofixable": true, + "autofix": [ + { + "start": 7, + "end": 23, + "replacementText": "d" + } + ], + "suggest": "", + "rule": "\"import default as ...\" is not supported (arkts-no-import-default-as)" + } + ] +} \ No newline at end of file diff --git a/linter-4.2/test_rules/rule120.ts.relax.json b/linter-4.2/test_rules/rule120.ts.relax.json new file mode 100644 index 000000000..13f13363f --- /dev/null +++ b/linter-4.2/test_rules/rule120.ts.relax.json @@ -0,0 +1,3 @@ +{ + "nodes": [] +} \ No newline at end of file diff --git a/linter-4.2/test_rules/rule120.ts.strict.json b/linter-4.2/test_rules/rule120.ts.strict.json new file mode 100644 index 000000000..4f5b8f369 --- /dev/null +++ b/linter-4.2/test_rules/rule120.ts.strict.json @@ -0,0 +1,11 @@ +{ + "nodes": [ + { + "line": 1, + "column": 10, + "problem": "DefaultImport", + "suggest": "", + "rule": "\"import default as ...\" is not supported (arkts-no-import-default-as)" + } + ] +} \ No newline at end of file diff --git a/linter-4.2/test_rules/rule121.ts b/linter-4.2/test_rules/rule121.ts new file mode 100644 index 000000000..809e44343 --- /dev/null +++ b/linter-4.2/test_rules/rule121.ts @@ -0,0 +1 @@ +import m = require("mod") \ No newline at end of file diff --git a/linter-4.2/test_rules/rule121.ts.autofix.json b/linter-4.2/test_rules/rule121.ts.autofix.json new file mode 100644 index 000000000..197c2ea1b --- /dev/null +++ b/linter-4.2/test_rules/rule121.ts.autofix.json @@ -0,0 +1,12 @@ +{ + "nodes": [ + { + "line": 1, + "column": 1, + "problem": "ImportAssignment", + "autofixable": false, + "suggest": "", + "rule": "\"require\" and \"import\" assignment are not supported (arkts-no-require)" + } + ] +} \ No newline at end of file diff --git a/linter-4.2/test_rules/rule121.ts.relax.json b/linter-4.2/test_rules/rule121.ts.relax.json new file mode 100644 index 000000000..03cee4fb6 --- /dev/null +++ b/linter-4.2/test_rules/rule121.ts.relax.json @@ -0,0 +1,11 @@ +{ + "nodes": [ + { + "line": 1, + "column": 1, + "problem": "ImportAssignment", + "suggest": "", + "rule": "\"require\" and \"import\" assignment are not supported (arkts-no-require)" + } + ] +} \ No newline at end of file diff --git a/linter-4.2/test_rules/rule121.ts.strict.json b/linter-4.2/test_rules/rule121.ts.strict.json new file mode 100644 index 000000000..03cee4fb6 --- /dev/null +++ b/linter-4.2/test_rules/rule121.ts.strict.json @@ -0,0 +1,11 @@ +{ + "nodes": [ + { + "line": 1, + "column": 1, + "problem": "ImportAssignment", + "suggest": "", + "rule": "\"require\" and \"import\" assignment are not supported (arkts-no-require)" + } + ] +} \ No newline at end of file diff --git a/linter-4.2/test_rules/rule125.ts b/linter-4.2/test_rules/rule125.ts new file mode 100644 index 000000000..094f9e773 --- /dev/null +++ b/linter-4.2/test_rules/rule125.ts @@ -0,0 +1,13 @@ + // module1 + export class Class1 { + // ... + } + export class Class2 { + // ... + } + + // module2 + export * as utilities from "module1" + + // consumer module + import { utilities } from "module2" \ No newline at end of file diff --git a/linter-4.2/test_rules/rule125.ts.autofix.json b/linter-4.2/test_rules/rule125.ts.autofix.json new file mode 100644 index 000000000..b5ef60319 --- /dev/null +++ b/linter-4.2/test_rules/rule125.ts.autofix.json @@ -0,0 +1,19 @@ +{ + "nodes": [ + { + "line": 10, + "column": 5, + "problem": "LimitedReExporting", + "autofixable": false, + "suggest": "", + "rule": "Re-exporting is supported with restrictions (arkts-limited-reexport)" + }, + { + "line": 13, + "column": 5, + "problem": "ImportAfterStatement", + "autofixable": false, + "rule": "\"import\" statements after other statements are not allowed (arkts-no-misplaced-imports)" + } + ] +} \ No newline at end of file diff --git a/linter-4.2/test_rules/rule125.ts.relax.json b/linter-4.2/test_rules/rule125.ts.relax.json new file mode 100644 index 000000000..0a9e3e3bf --- /dev/null +++ b/linter-4.2/test_rules/rule125.ts.relax.json @@ -0,0 +1,17 @@ +{ + "nodes": [ + { + "line": 10, + "column": 5, + "problem": "LimitedReExporting", + "suggest": "", + "rule": "Re-exporting is supported with restrictions (arkts-limited-reexport)" + }, + { + "line": 13, + "column": 5, + "problem": "ImportAfterStatement", + "rule": "\"import\" statements after other statements are not allowed (arkts-no-misplaced-imports)" + } + ] +} \ No newline at end of file diff --git a/linter-4.2/test_rules/rule125.ts.strict.json b/linter-4.2/test_rules/rule125.ts.strict.json new file mode 100644 index 000000000..0a9e3e3bf --- /dev/null +++ b/linter-4.2/test_rules/rule125.ts.strict.json @@ -0,0 +1,17 @@ +{ + "nodes": [ + { + "line": 10, + "column": 5, + "problem": "LimitedReExporting", + "suggest": "", + "rule": "Re-exporting is supported with restrictions (arkts-limited-reexport)" + }, + { + "line": 13, + "column": 5, + "problem": "ImportAfterStatement", + "rule": "\"import\" statements after other statements are not allowed (arkts-no-misplaced-imports)" + } + ] +} \ No newline at end of file diff --git a/linter-4.2/test_rules/rule126.ts b/linter-4.2/test_rules/rule126.ts new file mode 100644 index 000000000..8ded9440a --- /dev/null +++ b/linter-4.2/test_rules/rule126.ts @@ -0,0 +1,12 @@ + // module1 + export = Point + + class Point { + constructor(x: number, y: number) {} + static origin = new Point(0, 0) + } + + // module2 + import Pt = require("module1") + + let p = Pt.origin diff --git a/linter-4.2/test_rules/rule126.ts.autofix.json b/linter-4.2/test_rules/rule126.ts.autofix.json new file mode 100644 index 000000000..8e115e122 --- /dev/null +++ b/linter-4.2/test_rules/rule126.ts.autofix.json @@ -0,0 +1,28 @@ +{ + "nodes": [ + { + "line": 2, + "column": 5, + "problem": "ExportAssignment", + "autofixable": false, + "suggest": "", + "rule": "\"export = ...\" assignment is not supported (arkts-no-export-assignment)" + }, + { + "line": 10, + "column": 5, + "problem": "ImportAssignment", + "autofixable": false, + "suggest": "", + "rule": "\"require\" and \"import\" assignment are not supported (arkts-no-require)" + }, + { + "line": 12, + "column": 9, + "problem": "AnyType", + "autofixable": false, + "suggest": "", + "rule": "Use explicit types instead of \"any\", \"unknown\" (arkts-no-any-unknown)" + } + ] +} \ No newline at end of file diff --git a/linter-4.2/test_rules/rule126.ts.relax.json b/linter-4.2/test_rules/rule126.ts.relax.json new file mode 100644 index 000000000..161b8ec8e --- /dev/null +++ b/linter-4.2/test_rules/rule126.ts.relax.json @@ -0,0 +1,25 @@ +{ + "nodes": [ + { + "line": 2, + "column": 5, + "problem": "ExportAssignment", + "suggest": "", + "rule": "\"export = ...\" assignment is not supported (arkts-no-export-assignment)" + }, + { + "line": 10, + "column": 5, + "problem": "ImportAssignment", + "suggest": "", + "rule": "\"require\" and \"import\" assignment are not supported (arkts-no-require)" + }, + { + "line": 12, + "column": 9, + "problem": "AnyType", + "suggest": "", + "rule": "Use explicit types instead of \"any\", \"unknown\" (arkts-no-any-unknown)" + } + ] +} \ No newline at end of file diff --git a/linter-4.2/test_rules/rule126.ts.strict.json b/linter-4.2/test_rules/rule126.ts.strict.json new file mode 100644 index 000000000..161b8ec8e --- /dev/null +++ b/linter-4.2/test_rules/rule126.ts.strict.json @@ -0,0 +1,25 @@ +{ + "nodes": [ + { + "line": 2, + "column": 5, + "problem": "ExportAssignment", + "suggest": "", + "rule": "\"export = ...\" assignment is not supported (arkts-no-export-assignment)" + }, + { + "line": 10, + "column": 5, + "problem": "ImportAssignment", + "suggest": "", + "rule": "\"require\" and \"import\" assignment are not supported (arkts-no-require)" + }, + { + "line": 12, + "column": 9, + "problem": "AnyType", + "suggest": "", + "rule": "Use explicit types instead of \"any\", \"unknown\" (arkts-no-any-unknown)" + } + ] +} \ No newline at end of file diff --git a/linter-4.2/test_rules/rule127.ts b/linter-4.2/test_rules/rule127.ts new file mode 100644 index 000000000..903d61a6d --- /dev/null +++ b/linter-4.2/test_rules/rule127.ts @@ -0,0 +1,12 @@ + // Explicitly exported class: + export class Class1 { + // ... + } + + // Declared class later exported through export type ... + class Class2 { + // ... + } + + // This is not supported: + export type { Class2 } \ No newline at end of file diff --git a/linter-4.2/test_rules/rule127.ts.autofix.json b/linter-4.2/test_rules/rule127.ts.autofix.json new file mode 100644 index 000000000..c32c0f461 --- /dev/null +++ b/linter-4.2/test_rules/rule127.ts.autofix.json @@ -0,0 +1,19 @@ +{ + "nodes": [ + { + "line": 12, + "column": 5, + "problem": "TypeOnlyExport", + "autofixable": true, + "autofix": [ + { + "start": 218, + "end": 240, + "replacementText": "export { Class2 };" + } + ], + "suggest": "", + "rule": "Special \"export type\" declarations are not supported (arkts-no-special-exports)" + } + ] +} \ No newline at end of file diff --git a/linter-4.2/test_rules/rule127.ts.relax.json b/linter-4.2/test_rules/rule127.ts.relax.json new file mode 100644 index 000000000..13f13363f --- /dev/null +++ b/linter-4.2/test_rules/rule127.ts.relax.json @@ -0,0 +1,3 @@ +{ + "nodes": [] +} \ No newline at end of file diff --git a/linter-4.2/test_rules/rule127.ts.strict.json b/linter-4.2/test_rules/rule127.ts.strict.json new file mode 100644 index 000000000..35f1a5889 --- /dev/null +++ b/linter-4.2/test_rules/rule127.ts.strict.json @@ -0,0 +1,11 @@ +{ + "nodes": [ + { + "line": 12, + "column": 5, + "problem": "TypeOnlyExport", + "suggest": "", + "rule": "Special \"export type\" declarations are not supported (arkts-no-special-exports)" + } + ] +} \ No newline at end of file diff --git a/linter-4.2/test_rules/rule128.ts b/linter-4.2/test_rules/rule128.ts new file mode 100644 index 000000000..f3b0dd6f0 --- /dev/null +++ b/linter-4.2/test_rules/rule128.ts @@ -0,0 +1,3 @@ +declare module "someModule" { + export function normalize(s : string) : string; +} \ No newline at end of file diff --git a/linter-4.2/test_rules/rule128.ts.autofix.json b/linter-4.2/test_rules/rule128.ts.autofix.json new file mode 100644 index 000000000..fea184e9c --- /dev/null +++ b/linter-4.2/test_rules/rule128.ts.autofix.json @@ -0,0 +1,12 @@ +{ + "nodes": [ + { + "line": 1, + "column": 1, + "problem": "ShorthandAmbientModuleDecl", + "autofixable": false, + "suggest": "", + "rule": "Ambient module declaration is not supported (arkts-no-ambient-decls)" + } + ] +} \ No newline at end of file diff --git a/linter-4.2/test_rules/rule128.ts.relax.json b/linter-4.2/test_rules/rule128.ts.relax.json new file mode 100644 index 000000000..49937b6c7 --- /dev/null +++ b/linter-4.2/test_rules/rule128.ts.relax.json @@ -0,0 +1,11 @@ +{ + "nodes": [ + { + "line": 1, + "column": 1, + "problem": "ShorthandAmbientModuleDecl", + "suggest": "", + "rule": "Ambient module declaration is not supported (arkts-no-ambient-decls)" + } + ] +} \ No newline at end of file diff --git a/linter-4.2/test_rules/rule128.ts.strict.json b/linter-4.2/test_rules/rule128.ts.strict.json new file mode 100644 index 000000000..49937b6c7 --- /dev/null +++ b/linter-4.2/test_rules/rule128.ts.strict.json @@ -0,0 +1,11 @@ +{ + "nodes": [ + { + "line": 1, + "column": 1, + "problem": "ShorthandAmbientModuleDecl", + "suggest": "", + "rule": "Ambient module declaration is not supported (arkts-no-ambient-decls)" + } + ] +} \ No newline at end of file diff --git a/linter-4.2/test_rules/rule129.ts b/linter-4.2/test_rules/rule129.ts new file mode 100644 index 000000000..17703ba31 --- /dev/null +++ b/linter-4.2/test_rules/rule129.ts @@ -0,0 +1,8 @@ + // Declaration: + declare module "*!text" { + const content: string + export default content + } + + // Consuming code: + import fileContent from "some.txt!text" \ No newline at end of file diff --git a/linter-4.2/test_rules/rule129.ts.autofix.json b/linter-4.2/test_rules/rule129.ts.autofix.json new file mode 100644 index 000000000..cd88007bd --- /dev/null +++ b/linter-4.2/test_rules/rule129.ts.autofix.json @@ -0,0 +1,43 @@ +{ + "nodes": [ + { + "line": 4, + "column": 9, + "problem": "NonDeclarationInNamespace", + "autofixable": false, + "suggest": "", + "rule": "Non-declaration statements in namespaces are not supported (arkts-no-ns-statements)" + }, + { + "line": 2, + "column": 5, + "problem": "ShorthandAmbientModuleDecl", + "autofixable": false, + "suggest": "", + "rule": "Ambient module declaration is not supported (arkts-no-ambient-decls)" + }, + { + "line": 2, + "column": 5, + "problem": "WildcardsInModuleName", + "autofixable": false, + "suggest": "", + "rule": "Wildcards in module names are not supported (arkts-no-module-wildcards)" + }, + { + "line": 8, + "column": 5, + "problem": "ImportAfterStatement", + "autofixable": false, + "rule": "\"import\" statements after other statements are not allowed (arkts-no-misplaced-imports)" + }, + { + "line": 2, + "column": 20, + "problem": "StrictDiagnostic", + "autofixable": false, + "suggest": "Invalid module name in augmentation, module '*!text' cannot be found.", + "rule": "Invalid module name in augmentation, module '*!text' cannot be found." + } + ] +} \ No newline at end of file diff --git a/linter-4.2/test_rules/rule129.ts.relax.json b/linter-4.2/test_rules/rule129.ts.relax.json new file mode 100644 index 000000000..498d178cb --- /dev/null +++ b/linter-4.2/test_rules/rule129.ts.relax.json @@ -0,0 +1,38 @@ +{ + "nodes": [ + { + "line": 4, + "column": 9, + "problem": "NonDeclarationInNamespace", + "suggest": "", + "rule": "Non-declaration statements in namespaces are not supported (arkts-no-ns-statements)" + }, + { + "line": 2, + "column": 5, + "problem": "ShorthandAmbientModuleDecl", + "suggest": "", + "rule": "Ambient module declaration is not supported (arkts-no-ambient-decls)" + }, + { + "line": 2, + "column": 5, + "problem": "WildcardsInModuleName", + "suggest": "", + "rule": "Wildcards in module names are not supported (arkts-no-module-wildcards)" + }, + { + "line": 8, + "column": 5, + "problem": "ImportAfterStatement", + "rule": "\"import\" statements after other statements are not allowed (arkts-no-misplaced-imports)" + }, + { + "line": 2, + "column": 20, + "problem": "StrictDiagnostic", + "suggest": "Invalid module name in augmentation, module '*!text' cannot be found.", + "rule": "Invalid module name in augmentation, module '*!text' cannot be found." + } + ] +} \ No newline at end of file diff --git a/linter-4.2/test_rules/rule129.ts.strict.json b/linter-4.2/test_rules/rule129.ts.strict.json new file mode 100644 index 000000000..498d178cb --- /dev/null +++ b/linter-4.2/test_rules/rule129.ts.strict.json @@ -0,0 +1,38 @@ +{ + "nodes": [ + { + "line": 4, + "column": 9, + "problem": "NonDeclarationInNamespace", + "suggest": "", + "rule": "Non-declaration statements in namespaces are not supported (arkts-no-ns-statements)" + }, + { + "line": 2, + "column": 5, + "problem": "ShorthandAmbientModuleDecl", + "suggest": "", + "rule": "Ambient module declaration is not supported (arkts-no-ambient-decls)" + }, + { + "line": 2, + "column": 5, + "problem": "WildcardsInModuleName", + "suggest": "", + "rule": "Wildcards in module names are not supported (arkts-no-module-wildcards)" + }, + { + "line": 8, + "column": 5, + "problem": "ImportAfterStatement", + "rule": "\"import\" statements after other statements are not allowed (arkts-no-misplaced-imports)" + }, + { + "line": 2, + "column": 20, + "problem": "StrictDiagnostic", + "suggest": "Invalid module name in augmentation, module '*!text' cannot be found.", + "rule": "Invalid module name in augmentation, module '*!text' cannot be found." + } + ] +} \ No newline at end of file diff --git a/linter-4.2/test_rules/rule13.ts b/linter-4.2/test_rules/rule13.ts new file mode 100644 index 000000000..9d38b7e33 --- /dev/null +++ b/linter-4.2/test_rules/rule13.ts @@ -0,0 +1,8 @@ + +var t: [number, string] = [3, "three"] +var n = t[0] +var s = t[1] + +let a: Object[] = [3, "three"] +let b = a[0] +let c = a[1] \ No newline at end of file diff --git a/linter-4.2/test_rules/rule13.ts.autofix.json b/linter-4.2/test_rules/rule13.ts.autofix.json new file mode 100644 index 000000000..d82cefdf1 --- /dev/null +++ b/linter-4.2/test_rules/rule13.ts.autofix.json @@ -0,0 +1,36 @@ +{ + "nodes": [ + { + "line": 2, + "column": 1, + "problem": "VarDeclaration", + "autofixable": false, + "suggest": "", + "rule": "Use \"let\" instead of \"var\" (arkts-no-var)" + }, + { + "line": 2, + "column": 8, + "problem": "TupleType", + "autofixable": false, + "suggest": "", + "rule": "Use \"Object[]\" instead of tuples (arkts-no-tuples)" + }, + { + "line": 3, + "column": 1, + "problem": "VarDeclaration", + "autofixable": false, + "suggest": "", + "rule": "Use \"let\" instead of \"var\" (arkts-no-var)" + }, + { + "line": 4, + "column": 1, + "problem": "VarDeclaration", + "autofixable": false, + "suggest": "", + "rule": "Use \"let\" instead of \"var\" (arkts-no-var)" + } + ] +} \ No newline at end of file diff --git a/linter-4.2/test_rules/rule13.ts.relax.json b/linter-4.2/test_rules/rule13.ts.relax.json new file mode 100644 index 000000000..2e8a011be --- /dev/null +++ b/linter-4.2/test_rules/rule13.ts.relax.json @@ -0,0 +1,11 @@ +{ + "nodes": [ + { + "line": 2, + "column": 8, + "problem": "TupleType", + "suggest": "", + "rule": "Use \"Object[]\" instead of tuples (arkts-no-tuples)" + } + ] +} \ No newline at end of file diff --git a/linter-4.2/test_rules/rule13.ts.strict.json b/linter-4.2/test_rules/rule13.ts.strict.json new file mode 100644 index 000000000..175484d2d --- /dev/null +++ b/linter-4.2/test_rules/rule13.ts.strict.json @@ -0,0 +1,32 @@ +{ + "nodes": [ + { + "line": 2, + "column": 1, + "problem": "VarDeclaration", + "suggest": "", + "rule": "Use \"let\" instead of \"var\" (arkts-no-var)" + }, + { + "line": 2, + "column": 8, + "problem": "TupleType", + "suggest": "", + "rule": "Use \"Object[]\" instead of tuples (arkts-no-tuples)" + }, + { + "line": 3, + "column": 1, + "problem": "VarDeclaration", + "suggest": "", + "rule": "Use \"let\" instead of \"var\" (arkts-no-var)" + }, + { + "line": 4, + "column": 1, + "problem": "VarDeclaration", + "suggest": "", + "rule": "Use \"let\" instead of \"var\" (arkts-no-var)" + } + ] +} \ No newline at end of file diff --git a/linter-4.2/test_rules/rule130.ts b/linter-4.2/test_rules/rule130.ts new file mode 100644 index 000000000..004066f8c --- /dev/null +++ b/linter-4.2/test_rules/rule130.ts @@ -0,0 +1,6 @@ + // math-lib.d.ts + export const isPrime(x: number): boolean + export as namespace mathLib + + // in script + mathLib.isPrime(2) \ No newline at end of file diff --git a/linter-4.2/test_rules/rule130.ts.autofix.json b/linter-4.2/test_rules/rule130.ts.autofix.json new file mode 100644 index 000000000..3d31ba721 --- /dev/null +++ b/linter-4.2/test_rules/rule130.ts.autofix.json @@ -0,0 +1,20 @@ +{ + "nodes": [ + { + "line": 2, + "column": 18, + "problem": "AnyType", + "autofixable": false, + "suggest": "", + "rule": "Use explicit types instead of \"any\", \"unknown\" (arkts-no-any-unknown)" + }, + { + "line": 3, + "column": 5, + "problem": "UMDModuleDefinition", + "autofixable": false, + "suggest": "", + "rule": "Universal module definitions (UMD) are not supported (arkts-no-umd)" + } + ] +} \ No newline at end of file diff --git a/linter-4.2/test_rules/rule130.ts.relax.json b/linter-4.2/test_rules/rule130.ts.relax.json new file mode 100644 index 000000000..6877821bc --- /dev/null +++ b/linter-4.2/test_rules/rule130.ts.relax.json @@ -0,0 +1,18 @@ +{ + "nodes": [ + { + "line": 2, + "column": 18, + "problem": "AnyType", + "suggest": "", + "rule": "Use explicit types instead of \"any\", \"unknown\" (arkts-no-any-unknown)" + }, + { + "line": 3, + "column": 5, + "problem": "UMDModuleDefinition", + "suggest": "", + "rule": "Universal module definitions (UMD) are not supported (arkts-no-umd)" + } + ] +} \ No newline at end of file diff --git a/linter-4.2/test_rules/rule130.ts.strict.json b/linter-4.2/test_rules/rule130.ts.strict.json new file mode 100644 index 000000000..6877821bc --- /dev/null +++ b/linter-4.2/test_rules/rule130.ts.strict.json @@ -0,0 +1,18 @@ +{ + "nodes": [ + { + "line": 2, + "column": 18, + "problem": "AnyType", + "suggest": "", + "rule": "Use explicit types instead of \"any\", \"unknown\" (arkts-no-any-unknown)" + }, + { + "line": 3, + "column": 5, + "problem": "UMDModuleDefinition", + "suggest": "", + "rule": "Universal module definitions (UMD) are not supported (arkts-no-umd)" + } + ] +} \ No newline at end of file diff --git a/linter-4.2/test_rules/rule132.ts b/linter-4.2/test_rules/rule132.ts new file mode 100644 index 000000000..2791db745 --- /dev/null +++ b/linter-4.2/test_rules/rule132.ts @@ -0,0 +1,9 @@ +class CustomError extends Error { + constructor(message?: string) { + // 'Error' breaks prototype chain here: + super(message) + + // Restore prototype chain: + Object.setPrototypeOf(this, new.target.prototype) + } +} \ No newline at end of file diff --git a/linter-4.2/test_rules/rule132.ts.autofix.json b/linter-4.2/test_rules/rule132.ts.autofix.json new file mode 100644 index 000000000..9002b4276 --- /dev/null +++ b/linter-4.2/test_rules/rule132.ts.autofix.json @@ -0,0 +1,28 @@ +{ + "nodes": [ + { + "line": 7, + "column": 9, + "problem": "LimitedStdLibApi", + "autofixable": false, + "suggest": "", + "rule": "Usage of standard library is restricted (arkts-limited-stdlib)" + }, + { + "line": 7, + "column": 48, + "problem": "Prototype", + "autofixable": false, + "suggest": "", + "rule": "Prototype assignment is not supported (arkts-no-prototype-assignment)" + }, + { + "line": 7, + "column": 37, + "problem": "NewTarget", + "autofixable": false, + "suggest": "", + "rule": "\"new.target\" is not supported (arkts-no-new-target)" + } + ] +} \ No newline at end of file diff --git a/linter-4.2/test_rules/rule132.ts.relax.json b/linter-4.2/test_rules/rule132.ts.relax.json new file mode 100644 index 000000000..192c3aa10 --- /dev/null +++ b/linter-4.2/test_rules/rule132.ts.relax.json @@ -0,0 +1,25 @@ +{ + "nodes": [ + { + "line": 7, + "column": 9, + "problem": "LimitedStdLibApi", + "suggest": "", + "rule": "Usage of standard library is restricted (arkts-limited-stdlib)" + }, + { + "line": 7, + "column": 48, + "problem": "Prototype", + "suggest": "", + "rule": "Prototype assignment is not supported (arkts-no-prototype-assignment)" + }, + { + "line": 7, + "column": 37, + "problem": "NewTarget", + "suggest": "", + "rule": "\"new.target\" is not supported (arkts-no-new-target)" + } + ] +} \ No newline at end of file diff --git a/linter-4.2/test_rules/rule132.ts.strict.json b/linter-4.2/test_rules/rule132.ts.strict.json new file mode 100644 index 000000000..192c3aa10 --- /dev/null +++ b/linter-4.2/test_rules/rule132.ts.strict.json @@ -0,0 +1,25 @@ +{ + "nodes": [ + { + "line": 7, + "column": 9, + "problem": "LimitedStdLibApi", + "suggest": "", + "rule": "Usage of standard library is restricted (arkts-limited-stdlib)" + }, + { + "line": 7, + "column": 48, + "problem": "Prototype", + "suggest": "", + "rule": "Prototype assignment is not supported (arkts-no-prototype-assignment)" + }, + { + "line": 7, + "column": 37, + "problem": "NewTarget", + "suggest": "", + "rule": "\"new.target\" is not supported (arkts-no-new-target)" + } + ] +} \ No newline at end of file diff --git a/linter-4.2/test_rules/rule133.ts b/linter-4.2/test_rules/rule133.ts new file mode 100644 index 000000000..255d5b5b7 --- /dev/null +++ b/linter-4.2/test_rules/rule133.ts @@ -0,0 +1 @@ +const zipUtil = await import("utils/create-zip-file") \ No newline at end of file diff --git a/linter-4.2/test_rules/rule133.ts.autofix.json b/linter-4.2/test_rules/rule133.ts.autofix.json new file mode 100644 index 000000000..932f141fb --- /dev/null +++ b/linter-4.2/test_rules/rule133.ts.autofix.json @@ -0,0 +1,12 @@ +{ + "nodes": [ + { + "line": 1, + "column": 7, + "problem": "AnyType", + "autofixable": false, + "suggest": "", + "rule": "Use explicit types instead of \"any\", \"unknown\" (arkts-no-any-unknown)" + } + ] +} \ No newline at end of file diff --git a/linter-4.2/test_rules/rule133.ts.relax.json b/linter-4.2/test_rules/rule133.ts.relax.json new file mode 100644 index 000000000..a15ec7e87 --- /dev/null +++ b/linter-4.2/test_rules/rule133.ts.relax.json @@ -0,0 +1,11 @@ +{ + "nodes": [ + { + "line": 1, + "column": 7, + "problem": "AnyType", + "suggest": "", + "rule": "Use explicit types instead of \"any\", \"unknown\" (arkts-no-any-unknown)" + } + ] +} \ No newline at end of file diff --git a/linter-4.2/test_rules/rule133.ts.strict.json b/linter-4.2/test_rules/rule133.ts.strict.json new file mode 100644 index 000000000..a15ec7e87 --- /dev/null +++ b/linter-4.2/test_rules/rule133.ts.strict.json @@ -0,0 +1,11 @@ +{ + "nodes": [ + { + "line": 1, + "column": 7, + "problem": "AnyType", + "suggest": "", + "rule": "Use explicit types instead of \"any\", \"unknown\" (arkts-no-any-unknown)" + } + ] +} \ No newline at end of file diff --git a/linter-4.2/test_rules/rule134.ts b/linter-4.2/test_rules/rule134.ts new file mode 100644 index 000000000..7d7780e28 --- /dev/null +++ b/linter-4.2/test_rules/rule134.ts @@ -0,0 +1,9 @@ +let x!: number // Hint: x will be initialized before usage + +initialize() + +function initialize() { + x = 10 +} + +console.log("x = " + x) \ No newline at end of file diff --git a/linter-4.2/test_rules/rule134.ts.autofix.json b/linter-4.2/test_rules/rule134.ts.autofix.json new file mode 100644 index 000000000..150cae524 --- /dev/null +++ b/linter-4.2/test_rules/rule134.ts.autofix.json @@ -0,0 +1,12 @@ +{ + "nodes": [ + { + "line": 1, + "column": 5, + "problem": "DefiniteAssignment", + "autofixable": false, + "suggest": "", + "rule": "Definite assignment assertions are not supported (arkts-no-definite-assignment)" + } + ] +} \ No newline at end of file diff --git a/linter-4.2/test_rules/rule134.ts.relax.json b/linter-4.2/test_rules/rule134.ts.relax.json new file mode 100644 index 000000000..2c977321c --- /dev/null +++ b/linter-4.2/test_rules/rule134.ts.relax.json @@ -0,0 +1,11 @@ +{ + "nodes": [ + { + "line": 1, + "column": 5, + "problem": "DefiniteAssignment", + "suggest": "", + "rule": "Definite assignment assertions are not supported (arkts-no-definite-assignment)" + } + ] +} \ No newline at end of file diff --git a/linter-4.2/test_rules/rule134.ts.strict.json b/linter-4.2/test_rules/rule134.ts.strict.json new file mode 100644 index 000000000..2c977321c --- /dev/null +++ b/linter-4.2/test_rules/rule134.ts.strict.json @@ -0,0 +1,11 @@ +{ + "nodes": [ + { + "line": 1, + "column": 5, + "problem": "DefiniteAssignment", + "suggest": "", + "rule": "Definite assignment assertions are not supported (arkts-no-definite-assignment)" + } + ] +} \ No newline at end of file diff --git a/linter-4.2/test_rules/rule135.ts b/linter-4.2/test_rules/rule135.ts new file mode 100644 index 000000000..1912fcad2 --- /dev/null +++ b/linter-4.2/test_rules/rule135.ts @@ -0,0 +1,8 @@ +var C = (function() { + function C(n: number) { + this.p = n // Compile-time error only with noImplicitThis + } + C.staticProperty = 0 + return C +})() +C.staticProperty = 1 \ No newline at end of file diff --git a/linter-4.2/test_rules/rule135.ts.autofix.json b/linter-4.2/test_rules/rule135.ts.autofix.json new file mode 100644 index 000000000..f6875492b --- /dev/null +++ b/linter-4.2/test_rules/rule135.ts.autofix.json @@ -0,0 +1,43 @@ +{ + "nodes": [ + { + "line": 1, + "column": 1, + "problem": "VarDeclaration", + "autofixable": false, + "suggest": "", + "rule": "Use \"let\" instead of \"var\" (arkts-no-var)" + }, + { + "line": 1, + "column": 10, + "problem": "FunctionExpression", + "autofixable": true, + "autofix": [ + { + "start": 9, + "end": 161, + "replacementText": "() => {\n function C(n: number) {\n this.p = n; // Compile-time error only with noImplicitThis\n }\n C.staticProperty = 0;\n return C;\n}" + } + ], + "suggest": "", + "rule": "Use arrow functions instead of function expressions (arkts-no-func-expressions)" + }, + { + "line": 2, + "column": 5, + "problem": "FunctionContainsThis", + "autofixable": false, + "suggest": "", + "rule": "Using \"this\" inside stand-alone functions is not supported (arkts-no-standalone-this)" + }, + { + "line": 2, + "column": 5, + "problem": "LocalFunction", + "autofixable": false, + "suggest": "", + "rule": "Nested functions are not supported (arkts-no-nested-funcs)" + } + ] +} \ No newline at end of file diff --git a/linter-4.2/test_rules/rule135.ts.relax.json b/linter-4.2/test_rules/rule135.ts.relax.json new file mode 100644 index 000000000..772a1f628 --- /dev/null +++ b/linter-4.2/test_rules/rule135.ts.relax.json @@ -0,0 +1,11 @@ +{ + "nodes": [ + { + "line": 2, + "column": 5, + "problem": "FunctionContainsThis", + "suggest": "", + "rule": "Using \"this\" inside stand-alone functions is not supported (arkts-no-standalone-this)" + } + ] +} \ No newline at end of file diff --git a/linter-4.2/test_rules/rule135.ts.strict.json b/linter-4.2/test_rules/rule135.ts.strict.json new file mode 100644 index 000000000..715908747 --- /dev/null +++ b/linter-4.2/test_rules/rule135.ts.strict.json @@ -0,0 +1,32 @@ +{ + "nodes": [ + { + "line": 1, + "column": 1, + "problem": "VarDeclaration", + "suggest": "", + "rule": "Use \"let\" instead of \"var\" (arkts-no-var)" + }, + { + "line": 1, + "column": 10, + "problem": "FunctionExpression", + "suggest": "", + "rule": "Use arrow functions instead of function expressions (arkts-no-func-expressions)" + }, + { + "line": 2, + "column": 5, + "problem": "FunctionContainsThis", + "suggest": "", + "rule": "Using \"this\" inside stand-alone functions is not supported (arkts-no-standalone-this)" + }, + { + "line": 2, + "column": 5, + "problem": "LocalFunction", + "suggest": "", + "rule": "Nested functions are not supported (arkts-no-nested-funcs)" + } + ] +} \ No newline at end of file diff --git a/linter-4.2/test_rules/rule136.ts b/linter-4.2/test_rules/rule136.ts new file mode 100644 index 000000000..41d0b5095 --- /dev/null +++ b/linter-4.2/test_rules/rule136.ts @@ -0,0 +1,13 @@ +var C = function(p: number) { + this.p = p // Compile-time error only with noImplicitThis +} + +C.prototype = { + m() { + console.log(this.p) + } +} + +C.prototype.q = function(r: number) { + return this.p == r +} \ No newline at end of file diff --git a/linter-4.2/test_rules/rule136.ts.autofix.json b/linter-4.2/test_rules/rule136.ts.autofix.json new file mode 100644 index 000000000..2ef10313e --- /dev/null +++ b/linter-4.2/test_rules/rule136.ts.autofix.json @@ -0,0 +1,68 @@ +{ + "nodes": [ + { + "line": 1, + "column": 1, + "problem": "VarDeclaration", + "autofixable": false, + "suggest": "", + "rule": "Use \"let\" instead of \"var\" (arkts-no-var)" + }, + { + "line": 1, + "column": 9, + "problem": "FunctionExpression", + "autofixable": false, + "suggest": "", + "rule": "Use arrow functions instead of function expressions (arkts-no-func-expressions)" + }, + { + "line": 1, + "column": 9, + "problem": "FunctionContainsThis", + "autofixable": false, + "suggest": "", + "rule": "Using \"this\" inside stand-alone functions is not supported (arkts-no-standalone-this)" + }, + { + "line": 5, + "column": 3, + "problem": "Prototype", + "autofixable": false, + "suggest": "", + "rule": "Prototype assignment is not supported (arkts-no-prototype-assignment)" + }, + { + "line": 5, + "column": 15, + "problem": "ObjectLiteralNoContextType", + "autofixable": false, + "suggest": "", + "rule": "Object literal must correspond to some explicitly declared class or interface (arkts-no-untyped-obj-literals)" + }, + { + "line": 11, + "column": 3, + "problem": "Prototype", + "autofixable": false, + "suggest": "", + "rule": "Prototype assignment is not supported (arkts-no-prototype-assignment)" + }, + { + "line": 11, + "column": 17, + "problem": "FunctionExpression", + "autofixable": false, + "suggest": "", + "rule": "Use arrow functions instead of function expressions (arkts-no-func-expressions)" + }, + { + "line": 11, + "column": 17, + "problem": "FunctionContainsThis", + "autofixable": false, + "suggest": "", + "rule": "Using \"this\" inside stand-alone functions is not supported (arkts-no-standalone-this)" + } + ] +} \ No newline at end of file diff --git a/linter-4.2/test_rules/rule136.ts.relax.json b/linter-4.2/test_rules/rule136.ts.relax.json new file mode 100644 index 000000000..f048f98be --- /dev/null +++ b/linter-4.2/test_rules/rule136.ts.relax.json @@ -0,0 +1,39 @@ +{ + "nodes": [ + { + "line": 1, + "column": 9, + "problem": "FunctionContainsThis", + "suggest": "", + "rule": "Using \"this\" inside stand-alone functions is not supported (arkts-no-standalone-this)" + }, + { + "line": 5, + "column": 3, + "problem": "Prototype", + "suggest": "", + "rule": "Prototype assignment is not supported (arkts-no-prototype-assignment)" + }, + { + "line": 5, + "column": 15, + "problem": "ObjectLiteralNoContextType", + "suggest": "", + "rule": "Object literal must correspond to some explicitly declared class or interface (arkts-no-untyped-obj-literals)" + }, + { + "line": 11, + "column": 3, + "problem": "Prototype", + "suggest": "", + "rule": "Prototype assignment is not supported (arkts-no-prototype-assignment)" + }, + { + "line": 11, + "column": 17, + "problem": "FunctionContainsThis", + "suggest": "", + "rule": "Using \"this\" inside stand-alone functions is not supported (arkts-no-standalone-this)" + } + ] +} \ No newline at end of file diff --git a/linter-4.2/test_rules/rule136.ts.strict.json b/linter-4.2/test_rules/rule136.ts.strict.json new file mode 100644 index 000000000..aa5d42bb1 --- /dev/null +++ b/linter-4.2/test_rules/rule136.ts.strict.json @@ -0,0 +1,60 @@ +{ + "nodes": [ + { + "line": 1, + "column": 1, + "problem": "VarDeclaration", + "suggest": "", + "rule": "Use \"let\" instead of \"var\" (arkts-no-var)" + }, + { + "line": 1, + "column": 9, + "problem": "FunctionExpression", + "suggest": "", + "rule": "Use arrow functions instead of function expressions (arkts-no-func-expressions)" + }, + { + "line": 1, + "column": 9, + "problem": "FunctionContainsThis", + "suggest": "", + "rule": "Using \"this\" inside stand-alone functions is not supported (arkts-no-standalone-this)" + }, + { + "line": 5, + "column": 3, + "problem": "Prototype", + "suggest": "", + "rule": "Prototype assignment is not supported (arkts-no-prototype-assignment)" + }, + { + "line": 5, + "column": 15, + "problem": "ObjectLiteralNoContextType", + "suggest": "", + "rule": "Object literal must correspond to some explicitly declared class or interface (arkts-no-untyped-obj-literals)" + }, + { + "line": 11, + "column": 3, + "problem": "Prototype", + "suggest": "", + "rule": "Prototype assignment is not supported (arkts-no-prototype-assignment)" + }, + { + "line": 11, + "column": 17, + "problem": "FunctionExpression", + "suggest": "", + "rule": "Use arrow functions instead of function expressions (arkts-no-func-expressions)" + }, + { + "line": 11, + "column": 17, + "problem": "FunctionContainsThis", + "suggest": "", + "rule": "Using \"this\" inside stand-alone functions is not supported (arkts-no-standalone-this)" + } + ] +} \ No newline at end of file diff --git a/linter-4.2/test_rules/rule137.ts b/linter-4.2/test_rules/rule137.ts new file mode 100644 index 000000000..32d166ee4 --- /dev/null +++ b/linter-4.2/test_rules/rule137.ts @@ -0,0 +1,5 @@ + // in a global file: + var abc = 100 + + // Refers to 'abc' from above. + globalThis.abc = 200 \ No newline at end of file diff --git a/linter-4.2/test_rules/rule137.ts.autofix.json b/linter-4.2/test_rules/rule137.ts.autofix.json new file mode 100644 index 000000000..9a5bf848d --- /dev/null +++ b/linter-4.2/test_rules/rule137.ts.autofix.json @@ -0,0 +1,20 @@ +{ + "nodes": [ + { + "line": 2, + "column": 5, + "problem": "VarDeclaration", + "autofixable": false, + "suggest": "", + "rule": "Use \"let\" instead of \"var\" (arkts-no-var)" + }, + { + "line": 5, + "column": 5, + "problem": "GlobalThis", + "autofixable": false, + "suggest": "", + "rule": "\"globalThis\" is not supported (arkts-no-globalthis)" + } + ] +} \ No newline at end of file diff --git a/linter-4.2/test_rules/rule137.ts.relax.json b/linter-4.2/test_rules/rule137.ts.relax.json new file mode 100644 index 000000000..5ca44f447 --- /dev/null +++ b/linter-4.2/test_rules/rule137.ts.relax.json @@ -0,0 +1,11 @@ +{ + "nodes": [ + { + "line": 5, + "column": 5, + "problem": "GlobalThis", + "suggest": "", + "rule": "\"globalThis\" is not supported (arkts-no-globalthis)" + } + ] +} \ No newline at end of file diff --git a/linter-4.2/test_rules/rule137.ts.strict.json b/linter-4.2/test_rules/rule137.ts.strict.json new file mode 100644 index 000000000..2db3ea825 --- /dev/null +++ b/linter-4.2/test_rules/rule137.ts.strict.json @@ -0,0 +1,18 @@ +{ + "nodes": [ + { + "line": 2, + "column": 5, + "problem": "VarDeclaration", + "suggest": "", + "rule": "Use \"let\" instead of \"var\" (arkts-no-var)" + }, + { + "line": 5, + "column": 5, + "problem": "GlobalThis", + "suggest": "", + "rule": "\"globalThis\" is not supported (arkts-no-globalthis)" + } + ] +} \ No newline at end of file diff --git a/linter-4.2/test_rules/rule138.ts b/linter-4.2/test_rules/rule138.ts new file mode 100644 index 000000000..7f0361417 --- /dev/null +++ b/linter-4.2/test_rules/rule138.ts @@ -0,0 +1,22 @@ +type Person = { + name: string + age: number + location: string +} + +type QuantumPerson = Omit + +let persons : Record = { + "Alice": { + name: "Alice", + age: 32, + location: "Shanghai" + }, + "Bob": { + name: "Bob", + age: 48, + location: "New York" + } +} +console.log(persons["Bob"].age) +console.log(persons["Rob"].age) // Runtime exception \ No newline at end of file diff --git a/linter-4.2/test_rules/rule138.ts.autofix.json b/linter-4.2/test_rules/rule138.ts.autofix.json new file mode 100644 index 000000000..7b5d89515 --- /dev/null +++ b/linter-4.2/test_rules/rule138.ts.autofix.json @@ -0,0 +1,36 @@ +{ + "nodes": [ + { + "line": 1, + "column": 15, + "problem": "ObjectTypeLiteral", + "autofixable": false, + "suggest": "", + "rule": "Object literals cannot be used as type declarations (arkts-no-obj-literals-as-types)" + }, + { + "line": 7, + "column": 22, + "problem": "UtilityType", + "autofixable": false, + "suggest": "", + "rule": "Some of utility types are not supported (arkts-no-utility-types)" + }, + { + "line": 10, + "column": 14, + "problem": "ObjectLiteralNoContextType", + "autofixable": false, + "suggest": "", + "rule": "Object literal must correspond to some explicitly declared class or interface (arkts-no-untyped-obj-literals)" + }, + { + "line": 15, + "column": 12, + "problem": "ObjectLiteralNoContextType", + "autofixable": false, + "suggest": "", + "rule": "Object literal must correspond to some explicitly declared class or interface (arkts-no-untyped-obj-literals)" + } + ] +} \ No newline at end of file diff --git a/linter-4.2/test_rules/rule138.ts.relax.json b/linter-4.2/test_rules/rule138.ts.relax.json new file mode 100644 index 000000000..e8cfb5be2 --- /dev/null +++ b/linter-4.2/test_rules/rule138.ts.relax.json @@ -0,0 +1,32 @@ +{ + "nodes": [ + { + "line": 1, + "column": 15, + "problem": "ObjectTypeLiteral", + "suggest": "", + "rule": "Object literals cannot be used as type declarations (arkts-no-obj-literals-as-types)" + }, + { + "line": 7, + "column": 22, + "problem": "UtilityType", + "suggest": "", + "rule": "Some of utility types are not supported (arkts-no-utility-types)" + }, + { + "line": 10, + "column": 14, + "problem": "ObjectLiteralNoContextType", + "suggest": "", + "rule": "Object literal must correspond to some explicitly declared class or interface (arkts-no-untyped-obj-literals)" + }, + { + "line": 15, + "column": 12, + "problem": "ObjectLiteralNoContextType", + "suggest": "", + "rule": "Object literal must correspond to some explicitly declared class or interface (arkts-no-untyped-obj-literals)" + } + ] +} \ No newline at end of file diff --git a/linter-4.2/test_rules/rule138.ts.strict.json b/linter-4.2/test_rules/rule138.ts.strict.json new file mode 100644 index 000000000..e8cfb5be2 --- /dev/null +++ b/linter-4.2/test_rules/rule138.ts.strict.json @@ -0,0 +1,32 @@ +{ + "nodes": [ + { + "line": 1, + "column": 15, + "problem": "ObjectTypeLiteral", + "suggest": "", + "rule": "Object literals cannot be used as type declarations (arkts-no-obj-literals-as-types)" + }, + { + "line": 7, + "column": 22, + "problem": "UtilityType", + "suggest": "", + "rule": "Some of utility types are not supported (arkts-no-utility-types)" + }, + { + "line": 10, + "column": 14, + "problem": "ObjectLiteralNoContextType", + "suggest": "", + "rule": "Object literal must correspond to some explicitly declared class or interface (arkts-no-untyped-obj-literals)" + }, + { + "line": 15, + "column": 12, + "problem": "ObjectLiteralNoContextType", + "suggest": "", + "rule": "Object literal must correspond to some explicitly declared class or interface (arkts-no-untyped-obj-literals)" + } + ] +} \ No newline at end of file diff --git a/linter-4.2/test_rules/rule139.ts b/linter-4.2/test_rules/rule139.ts new file mode 100644 index 000000000..bcbd60a52 --- /dev/null +++ b/linter-4.2/test_rules/rule139.ts @@ -0,0 +1,23 @@ +class MyImage { + // ... +} + +function readImage( + path: string, callback: (err: any, image: MyImage) => void +) +{ + // ... +} + +function readFileSync(path : string) : number[] { + return [] +} + +function decodeImageSync(contrents : number[]) { + // ... +} + +readImage.sync = (path: string) => { + const contents = readFileSync(path) + return decodeImageSync(contents) +} \ No newline at end of file diff --git a/linter-4.2/test_rules/rule139.ts.autofix.json b/linter-4.2/test_rules/rule139.ts.autofix.json new file mode 100644 index 000000000..889c717b6 --- /dev/null +++ b/linter-4.2/test_rules/rule139.ts.autofix.json @@ -0,0 +1,57 @@ +{ + "copyright": [ + "Copyright (c) 2023-2023 Huawei Device Co., Ltd.", + "Licensed under the Apache License, Version 2.0 (the 'License');", + "you may not use this file except in compliance with the License.", + "You may obtain a copy of the License at", + "", + "http://www.apache.org/licenses/LICENSE-2.0", + "", + "Unless required by applicable law or agreed to in writing, software", + "distributed under the License is distributed on an 'AS IS' BASIS,", + "WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.", + "See the License for the specific language governing permissions and", + "limitations under the License." + ], + "nodes": [ + { + "line": 6, + "column": 35, + "problem": "AnyType", + "autofixable": false, + "suggest": "", + "rule": "Use explicit types instead of \"any\", \"unknown\" (arkts-no-any-unknown)" + }, + { + "line": 20, + "column": 1, + "problem": "MethodReassignment", + "autofixable": false, + "suggest": "", + "rule": "Reassigning object methods is not supported (arkts-no-method-reassignment)" + }, + { + "line": 20, + "column": 1, + "problem": "PropertyDeclOnFunction", + "autofixable": false, + "suggest": "", + "rule": "Declaring properties on functions is not supported (arkts-no-func-props)" + }, + { + "line": 20, + "column": 18, + "problem": "LimitedReturnTypeInference", + "autofixable": true, + "autofix": [ + { + "start": 292, + "end": 292, + "replacementText": ": void" + } + ], + "suggest": "", + "rule": "Function return type inference is limited (arkts-no-implicit-return-types)" + } + ] +} \ No newline at end of file diff --git a/linter-4.2/test_rules/rule139.ts.relax.json b/linter-4.2/test_rules/rule139.ts.relax.json new file mode 100644 index 000000000..b7b7c9f37 --- /dev/null +++ b/linter-4.2/test_rules/rule139.ts.relax.json @@ -0,0 +1,39 @@ +{ + "copyright": [ + "Copyright (c) 2023-2023 Huawei Device Co., Ltd.", + "Licensed under the Apache License, Version 2.0 (the 'License');", + "you may not use this file except in compliance with the License.", + "You may obtain a copy of the License at", + "", + "http://www.apache.org/licenses/LICENSE-2.0", + "", + "Unless required by applicable law or agreed to in writing, software", + "distributed under the License is distributed on an 'AS IS' BASIS,", + "WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.", + "See the License for the specific language governing permissions and", + "limitations under the License." + ], + "nodes": [ + { + "line": 6, + "column": 35, + "problem": "AnyType", + "suggest": "", + "rule": "Use explicit types instead of \"any\", \"unknown\" (arkts-no-any-unknown)" + }, + { + "line": 20, + "column": 1, + "problem": "MethodReassignment", + "suggest": "", + "rule": "Reassigning object methods is not supported (arkts-no-method-reassignment)" + }, + { + "line": 20, + "column": 1, + "problem": "PropertyDeclOnFunction", + "suggest": "", + "rule": "Declaring properties on functions is not supported (arkts-no-func-props)" + } + ] +} \ No newline at end of file diff --git a/linter-4.2/test_rules/rule139.ts.strict.json b/linter-4.2/test_rules/rule139.ts.strict.json new file mode 100644 index 000000000..29d461209 --- /dev/null +++ b/linter-4.2/test_rules/rule139.ts.strict.json @@ -0,0 +1,46 @@ +{ + "copyright": [ + "Copyright (c) 2023-2023 Huawei Device Co., Ltd.", + "Licensed under the Apache License, Version 2.0 (the 'License');", + "you may not use this file except in compliance with the License.", + "You may obtain a copy of the License at", + "", + "http://www.apache.org/licenses/LICENSE-2.0", + "", + "Unless required by applicable law or agreed to in writing, software", + "distributed under the License is distributed on an 'AS IS' BASIS,", + "WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.", + "See the License for the specific language governing permissions and", + "limitations under the License." + ], + "nodes": [ + { + "line": 6, + "column": 35, + "problem": "AnyType", + "suggest": "", + "rule": "Use explicit types instead of \"any\", \"unknown\" (arkts-no-any-unknown)" + }, + { + "line": 20, + "column": 1, + "problem": "MethodReassignment", + "suggest": "", + "rule": "Reassigning object methods is not supported (arkts-no-method-reassignment)" + }, + { + "line": 20, + "column": 1, + "problem": "PropertyDeclOnFunction", + "suggest": "", + "rule": "Declaring properties on functions is not supported (arkts-no-func-props)" + }, + { + "line": 20, + "column": 18, + "problem": "LimitedReturnTypeInference", + "suggest": "", + "rule": "Function return type inference is limited (arkts-no-implicit-return-types)" + } + ] +} \ No newline at end of file diff --git a/linter-4.2/test_rules/rule14.ts b/linter-4.2/test_rules/rule14.ts new file mode 100644 index 000000000..c280a753d --- /dev/null +++ b/linter-4.2/test_rules/rule14.ts @@ -0,0 +1,8 @@ +type DescribableFunction = { + description: string + (someArg: number): string // call signature +} + +function doSomething(fn: DescribableFunction): void { + console.log(fn.description + " returned " + fn(6)) +} \ No newline at end of file diff --git a/linter-4.2/test_rules/rule14.ts.autofix.json b/linter-4.2/test_rules/rule14.ts.autofix.json new file mode 100644 index 000000000..2448bab5a --- /dev/null +++ b/linter-4.2/test_rules/rule14.ts.autofix.json @@ -0,0 +1,20 @@ +{ + "nodes": [ + { + "line": 1, + "column": 28, + "problem": "ObjectTypeLiteral", + "autofixable": false, + "suggest": "", + "rule": "Object literals cannot be used as type declarations (arkts-no-obj-literals-as-types)" + }, + { + "line": 3, + "column": 5, + "problem": "CallSignature", + "autofixable": false, + "suggest": "", + "rule": "Use \"class\" instead of a type with call signature (arkts-no-call-signatures)" + } + ] +} \ No newline at end of file diff --git a/linter-4.2/test_rules/rule14.ts.relax.json b/linter-4.2/test_rules/rule14.ts.relax.json new file mode 100644 index 000000000..37abba905 --- /dev/null +++ b/linter-4.2/test_rules/rule14.ts.relax.json @@ -0,0 +1,18 @@ +{ + "nodes": [ + { + "line": 1, + "column": 28, + "problem": "ObjectTypeLiteral", + "suggest": "", + "rule": "Object literals cannot be used as type declarations (arkts-no-obj-literals-as-types)" + }, + { + "line": 3, + "column": 5, + "problem": "CallSignature", + "suggest": "", + "rule": "Use \"class\" instead of a type with call signature (arkts-no-call-signatures)" + } + ] +} \ No newline at end of file diff --git a/linter-4.2/test_rules/rule14.ts.strict.json b/linter-4.2/test_rules/rule14.ts.strict.json new file mode 100644 index 000000000..37abba905 --- /dev/null +++ b/linter-4.2/test_rules/rule14.ts.strict.json @@ -0,0 +1,18 @@ +{ + "nodes": [ + { + "line": 1, + "column": 28, + "problem": "ObjectTypeLiteral", + "suggest": "", + "rule": "Object literals cannot be used as type declarations (arkts-no-obj-literals-as-types)" + }, + { + "line": 3, + "column": 5, + "problem": "CallSignature", + "suggest": "", + "rule": "Use \"class\" instead of a type with call signature (arkts-no-call-signatures)" + } + ] +} \ No newline at end of file diff --git a/linter-4.2/test_rules/rule140.ts b/linter-4.2/test_rules/rule140.ts new file mode 100644 index 000000000..bcbd60a52 --- /dev/null +++ b/linter-4.2/test_rules/rule140.ts @@ -0,0 +1,23 @@ +class MyImage { + // ... +} + +function readImage( + path: string, callback: (err: any, image: MyImage) => void +) +{ + // ... +} + +function readFileSync(path : string) : number[] { + return [] +} + +function decodeImageSync(contrents : number[]) { + // ... +} + +readImage.sync = (path: string) => { + const contents = readFileSync(path) + return decodeImageSync(contents) +} \ No newline at end of file diff --git a/linter-4.2/test_rules/rule140.ts.autofix.json b/linter-4.2/test_rules/rule140.ts.autofix.json new file mode 100644 index 000000000..889c717b6 --- /dev/null +++ b/linter-4.2/test_rules/rule140.ts.autofix.json @@ -0,0 +1,57 @@ +{ + "copyright": [ + "Copyright (c) 2023-2023 Huawei Device Co., Ltd.", + "Licensed under the Apache License, Version 2.0 (the 'License');", + "you may not use this file except in compliance with the License.", + "You may obtain a copy of the License at", + "", + "http://www.apache.org/licenses/LICENSE-2.0", + "", + "Unless required by applicable law or agreed to in writing, software", + "distributed under the License is distributed on an 'AS IS' BASIS,", + "WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.", + "See the License for the specific language governing permissions and", + "limitations under the License." + ], + "nodes": [ + { + "line": 6, + "column": 35, + "problem": "AnyType", + "autofixable": false, + "suggest": "", + "rule": "Use explicit types instead of \"any\", \"unknown\" (arkts-no-any-unknown)" + }, + { + "line": 20, + "column": 1, + "problem": "MethodReassignment", + "autofixable": false, + "suggest": "", + "rule": "Reassigning object methods is not supported (arkts-no-method-reassignment)" + }, + { + "line": 20, + "column": 1, + "problem": "PropertyDeclOnFunction", + "autofixable": false, + "suggest": "", + "rule": "Declaring properties on functions is not supported (arkts-no-func-props)" + }, + { + "line": 20, + "column": 18, + "problem": "LimitedReturnTypeInference", + "autofixable": true, + "autofix": [ + { + "start": 292, + "end": 292, + "replacementText": ": void" + } + ], + "suggest": "", + "rule": "Function return type inference is limited (arkts-no-implicit-return-types)" + } + ] +} \ No newline at end of file diff --git a/linter-4.2/test_rules/rule140.ts.relax.json b/linter-4.2/test_rules/rule140.ts.relax.json new file mode 100644 index 000000000..b7b7c9f37 --- /dev/null +++ b/linter-4.2/test_rules/rule140.ts.relax.json @@ -0,0 +1,39 @@ +{ + "copyright": [ + "Copyright (c) 2023-2023 Huawei Device Co., Ltd.", + "Licensed under the Apache License, Version 2.0 (the 'License');", + "you may not use this file except in compliance with the License.", + "You may obtain a copy of the License at", + "", + "http://www.apache.org/licenses/LICENSE-2.0", + "", + "Unless required by applicable law or agreed to in writing, software", + "distributed under the License is distributed on an 'AS IS' BASIS,", + "WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.", + "See the License for the specific language governing permissions and", + "limitations under the License." + ], + "nodes": [ + { + "line": 6, + "column": 35, + "problem": "AnyType", + "suggest": "", + "rule": "Use explicit types instead of \"any\", \"unknown\" (arkts-no-any-unknown)" + }, + { + "line": 20, + "column": 1, + "problem": "MethodReassignment", + "suggest": "", + "rule": "Reassigning object methods is not supported (arkts-no-method-reassignment)" + }, + { + "line": 20, + "column": 1, + "problem": "PropertyDeclOnFunction", + "suggest": "", + "rule": "Declaring properties on functions is not supported (arkts-no-func-props)" + } + ] +} \ No newline at end of file diff --git a/linter-4.2/test_rules/rule140.ts.strict.json b/linter-4.2/test_rules/rule140.ts.strict.json new file mode 100644 index 000000000..29d461209 --- /dev/null +++ b/linter-4.2/test_rules/rule140.ts.strict.json @@ -0,0 +1,46 @@ +{ + "copyright": [ + "Copyright (c) 2023-2023 Huawei Device Co., Ltd.", + "Licensed under the Apache License, Version 2.0 (the 'License');", + "you may not use this file except in compliance with the License.", + "You may obtain a copy of the License at", + "", + "http://www.apache.org/licenses/LICENSE-2.0", + "", + "Unless required by applicable law or agreed to in writing, software", + "distributed under the License is distributed on an 'AS IS' BASIS,", + "WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.", + "See the License for the specific language governing permissions and", + "limitations under the License." + ], + "nodes": [ + { + "line": 6, + "column": 35, + "problem": "AnyType", + "suggest": "", + "rule": "Use explicit types instead of \"any\", \"unknown\" (arkts-no-any-unknown)" + }, + { + "line": 20, + "column": 1, + "problem": "MethodReassignment", + "suggest": "", + "rule": "Reassigning object methods is not supported (arkts-no-method-reassignment)" + }, + { + "line": 20, + "column": 1, + "problem": "PropertyDeclOnFunction", + "suggest": "", + "rule": "Declaring properties on functions is not supported (arkts-no-func-props)" + }, + { + "line": 20, + "column": 18, + "problem": "LimitedReturnTypeInference", + "suggest": "", + "rule": "Function return type inference is limited (arkts-no-implicit-return-types)" + } + ] +} \ No newline at end of file diff --git a/linter-4.2/test_rules/rule141.ts b/linter-4.2/test_rules/rule141.ts new file mode 100644 index 000000000..a0ebc2f84 --- /dev/null +++ b/linter-4.2/test_rules/rule141.ts @@ -0,0 +1,4 @@ +function foo(arr: readonly string[]) { + arr.slice() // OK + arr.push("hello!") // Compile-time error +} \ No newline at end of file diff --git a/linter-4.2/test_rules/rule141.ts.autofix.json b/linter-4.2/test_rules/rule141.ts.autofix.json new file mode 100644 index 000000000..4843ef02e --- /dev/null +++ b/linter-4.2/test_rules/rule141.ts.autofix.json @@ -0,0 +1,19 @@ +{ + "nodes": [ + { + "line": 1, + "column": 19, + "problem": "ReadonlyArr", + "autofixable": true, + "autofix": [ + { + "start": 18, + "end": 35, + "replacementText": "string[]" + } + ], + "suggest": "", + "rule": "\"readonly T[]\" syntax is not supported (arkts-no-readonly-params)" + } + ] +} \ No newline at end of file diff --git a/linter-4.2/test_rules/rule141.ts.relax.json b/linter-4.2/test_rules/rule141.ts.relax.json new file mode 100644 index 000000000..13f13363f --- /dev/null +++ b/linter-4.2/test_rules/rule141.ts.relax.json @@ -0,0 +1,3 @@ +{ + "nodes": [] +} \ No newline at end of file diff --git a/linter-4.2/test_rules/rule141.ts.strict.json b/linter-4.2/test_rules/rule141.ts.strict.json new file mode 100644 index 000000000..3d0ea4953 --- /dev/null +++ b/linter-4.2/test_rules/rule141.ts.strict.json @@ -0,0 +1,11 @@ +{ + "nodes": [ + { + "line": 1, + "column": 19, + "problem": "ReadonlyArr", + "suggest": "", + "rule": "\"readonly T[]\" syntax is not supported (arkts-no-readonly-params)" + } + ] +} \ No newline at end of file diff --git a/linter-4.2/test_rules/rule142.ts b/linter-4.2/test_rules/rule142.ts new file mode 100644 index 000000000..cbccf5be8 --- /dev/null +++ b/linter-4.2/test_rules/rule142.ts @@ -0,0 +1,8 @@ + // Type 'hello': + let x = "hello" as const + + // Type 'readonly [10, 20]': + let y = [10, 20] as const + + // Type '{ readonly text: "hello" }': + let z = { text: "hello" } as const \ No newline at end of file diff --git a/linter-4.2/test_rules/rule142.ts.autofix.json b/linter-4.2/test_rules/rule142.ts.autofix.json new file mode 100644 index 000000000..8da6f5f88 --- /dev/null +++ b/linter-4.2/test_rules/rule142.ts.autofix.json @@ -0,0 +1,36 @@ +{ + "nodes": [ + { + "line": 2, + "column": 13, + "problem": "ConstAssertion", + "autofixable": false, + "suggest": "", + "rule": "\"as const\" assertions are not supported (arkts-no-as-const)" + }, + { + "line": 5, + "column": 13, + "problem": "ConstAssertion", + "autofixable": false, + "suggest": "", + "rule": "\"as const\" assertions are not supported (arkts-no-as-const)" + }, + { + "line": 8, + "column": 13, + "problem": "ConstAssertion", + "autofixable": false, + "suggest": "", + "rule": "\"as const\" assertions are not supported (arkts-no-as-const)" + }, + { + "line": 8, + "column": 13, + "problem": "ObjectLiteralNoContextType", + "autofixable": false, + "suggest": "", + "rule": "Object literal must correspond to some explicitly declared class or interface (arkts-no-untyped-obj-literals)" + } + ] +} \ No newline at end of file diff --git a/linter-4.2/test_rules/rule142.ts.relax.json b/linter-4.2/test_rules/rule142.ts.relax.json new file mode 100644 index 000000000..f61e4269a --- /dev/null +++ b/linter-4.2/test_rules/rule142.ts.relax.json @@ -0,0 +1,32 @@ +{ + "nodes": [ + { + "line": 2, + "column": 13, + "problem": "ConstAssertion", + "suggest": "", + "rule": "\"as const\" assertions are not supported (arkts-no-as-const)" + }, + { + "line": 5, + "column": 13, + "problem": "ConstAssertion", + "suggest": "", + "rule": "\"as const\" assertions are not supported (arkts-no-as-const)" + }, + { + "line": 8, + "column": 13, + "problem": "ConstAssertion", + "suggest": "", + "rule": "\"as const\" assertions are not supported (arkts-no-as-const)" + }, + { + "line": 8, + "column": 13, + "problem": "ObjectLiteralNoContextType", + "suggest": "", + "rule": "Object literal must correspond to some explicitly declared class or interface (arkts-no-untyped-obj-literals)" + } + ] +} \ No newline at end of file diff --git a/linter-4.2/test_rules/rule142.ts.strict.json b/linter-4.2/test_rules/rule142.ts.strict.json new file mode 100644 index 000000000..f61e4269a --- /dev/null +++ b/linter-4.2/test_rules/rule142.ts.strict.json @@ -0,0 +1,32 @@ +{ + "nodes": [ + { + "line": 2, + "column": 13, + "problem": "ConstAssertion", + "suggest": "", + "rule": "\"as const\" assertions are not supported (arkts-no-as-const)" + }, + { + "line": 5, + "column": 13, + "problem": "ConstAssertion", + "suggest": "", + "rule": "\"as const\" assertions are not supported (arkts-no-as-const)" + }, + { + "line": 8, + "column": 13, + "problem": "ConstAssertion", + "suggest": "", + "rule": "\"as const\" assertions are not supported (arkts-no-as-const)" + }, + { + "line": 8, + "column": 13, + "problem": "ObjectLiteralNoContextType", + "suggest": "", + "rule": "Object literal must correspond to some explicitly declared class or interface (arkts-no-untyped-obj-literals)" + } + ] +} \ No newline at end of file diff --git a/linter-4.2/test_rules/rule145.ts b/linter-4.2/test_rules/rule145.ts new file mode 100644 index 000000000..74719e73d --- /dev/null +++ b/linter-4.2/test_rules/rule145.ts @@ -0,0 +1,16 @@ +class C { + n: number // Compile-time error only with strictPropertyInitialization + s: string // Compile-time error only with strictPropertyInitialization +} + +// Compile-time error only with noImplicitReturns +function foo(s: string): string { + if (s != "") { + console.log(s) + return s + } else { + console.log(s) + } +} + +let n: number = null // Compile-time error only with strictNullChecks \ No newline at end of file diff --git a/linter-4.2/test_rules/rule145.ts.autofix.json b/linter-4.2/test_rules/rule145.ts.autofix.json new file mode 100644 index 000000000..d5441fbcd --- /dev/null +++ b/linter-4.2/test_rules/rule145.ts.autofix.json @@ -0,0 +1,36 @@ +{ + "nodes": [ + { + "line": 2, + "column": 5, + "problem": "StrictDiagnostic", + "autofixable": false, + "suggest": "Property 'n' has no initializer and is not definitely assigned in the constructor.", + "rule": "Property 'n' has no initializer and is not definitely assigned in the constructor." + }, + { + "line": 3, + "column": 5, + "problem": "StrictDiagnostic", + "autofixable": false, + "suggest": "Property 's' has no initializer and is not definitely assigned in the constructor.", + "rule": "Property 's' has no initializer and is not definitely assigned in the constructor." + }, + { + "line": 7, + "column": 26, + "problem": "StrictDiagnostic", + "autofixable": false, + "suggest": "Function lacks ending return statement and return type does not include 'undefined'.", + "rule": "Function lacks ending return statement and return type does not include 'undefined'." + }, + { + "line": 16, + "column": 5, + "problem": "StrictDiagnostic", + "autofixable": false, + "suggest": "Type 'null' is not assignable to type 'number'.", + "rule": "Type 'null' is not assignable to type 'number'." + } + ] +} \ No newline at end of file diff --git a/linter-4.2/test_rules/rule145.ts.relax.json b/linter-4.2/test_rules/rule145.ts.relax.json new file mode 100644 index 000000000..7a0139ed3 --- /dev/null +++ b/linter-4.2/test_rules/rule145.ts.relax.json @@ -0,0 +1,32 @@ +{ + "nodes": [ + { + "line": 2, + "column": 5, + "problem": "StrictDiagnostic", + "suggest": "Property 'n' has no initializer and is not definitely assigned in the constructor.", + "rule": "Property 'n' has no initializer and is not definitely assigned in the constructor." + }, + { + "line": 3, + "column": 5, + "problem": "StrictDiagnostic", + "suggest": "Property 's' has no initializer and is not definitely assigned in the constructor.", + "rule": "Property 's' has no initializer and is not definitely assigned in the constructor." + }, + { + "line": 7, + "column": 26, + "problem": "StrictDiagnostic", + "suggest": "Function lacks ending return statement and return type does not include 'undefined'.", + "rule": "Function lacks ending return statement and return type does not include 'undefined'." + }, + { + "line": 16, + "column": 5, + "problem": "StrictDiagnostic", + "suggest": "Type 'null' is not assignable to type 'number'.", + "rule": "Type 'null' is not assignable to type 'number'." + } + ] +} \ No newline at end of file diff --git a/linter-4.2/test_rules/rule145.ts.strict.json b/linter-4.2/test_rules/rule145.ts.strict.json new file mode 100644 index 000000000..7a0139ed3 --- /dev/null +++ b/linter-4.2/test_rules/rule145.ts.strict.json @@ -0,0 +1,32 @@ +{ + "nodes": [ + { + "line": 2, + "column": 5, + "problem": "StrictDiagnostic", + "suggest": "Property 'n' has no initializer and is not definitely assigned in the constructor.", + "rule": "Property 'n' has no initializer and is not definitely assigned in the constructor." + }, + { + "line": 3, + "column": 5, + "problem": "StrictDiagnostic", + "suggest": "Property 's' has no initializer and is not definitely assigned in the constructor.", + "rule": "Property 's' has no initializer and is not definitely assigned in the constructor." + }, + { + "line": 7, + "column": 26, + "problem": "StrictDiagnostic", + "suggest": "Function lacks ending return statement and return type does not include 'undefined'.", + "rule": "Function lacks ending return statement and return type does not include 'undefined'." + }, + { + "line": 16, + "column": 5, + "problem": "StrictDiagnostic", + "suggest": "Type 'null' is not assignable to type 'number'.", + "rule": "Type 'null' is not assignable to type 'number'." + } + ] +} \ No newline at end of file diff --git a/linter-4.2/test_rules/rule146.ts b/linter-4.2/test_rules/rule146.ts new file mode 100644 index 000000000..ce6a9f844 --- /dev/null +++ b/linter-4.2/test_rules/rule146.ts @@ -0,0 +1,9 @@ + // @ts-nocheck + // ... + // Some code with switched off type checker + // ... + + let s1: string = null // No error, type checker suppressed + + // @ts-ignore + let s2: string = null // No error, type checker suppressed \ No newline at end of file diff --git a/linter-4.2/test_rules/rule146.ts.autofix.json b/linter-4.2/test_rules/rule146.ts.autofix.json new file mode 100644 index 000000000..f76f77acc --- /dev/null +++ b/linter-4.2/test_rules/rule146.ts.autofix.json @@ -0,0 +1,20 @@ +{ + "nodes": [ + { + "line": 1, + "column": 5, + "problem": "ErrorSuppression", + "autofixable": false, + "suggest": "", + "rule": "Switching off type checks with in-place comments is not allowed (arkts-strict-typing-required)" + }, + { + "line": 8, + "column": 5, + "problem": "ErrorSuppression", + "autofixable": false, + "suggest": "", + "rule": "Switching off type checks with in-place comments is not allowed (arkts-strict-typing-required)" + } + ] +} \ No newline at end of file diff --git a/linter-4.2/test_rules/rule146.ts.relax.json b/linter-4.2/test_rules/rule146.ts.relax.json new file mode 100644 index 000000000..4cf4a17db --- /dev/null +++ b/linter-4.2/test_rules/rule146.ts.relax.json @@ -0,0 +1,18 @@ +{ + "nodes": [ + { + "line": 1, + "column": 5, + "problem": "ErrorSuppression", + "suggest": "", + "rule": "Switching off type checks with in-place comments is not allowed (arkts-strict-typing-required)" + }, + { + "line": 8, + "column": 5, + "problem": "ErrorSuppression", + "suggest": "", + "rule": "Switching off type checks with in-place comments is not allowed (arkts-strict-typing-required)" + } + ] +} \ No newline at end of file diff --git a/linter-4.2/test_rules/rule146.ts.strict.json b/linter-4.2/test_rules/rule146.ts.strict.json new file mode 100644 index 000000000..4cf4a17db --- /dev/null +++ b/linter-4.2/test_rules/rule146.ts.strict.json @@ -0,0 +1,18 @@ +{ + "nodes": [ + { + "line": 1, + "column": 5, + "problem": "ErrorSuppression", + "suggest": "", + "rule": "Switching off type checks with in-place comments is not allowed (arkts-strict-typing-required)" + }, + { + "line": 8, + "column": 5, + "problem": "ErrorSuppression", + "suggest": "", + "rule": "Switching off type checks with in-place comments is not allowed (arkts-strict-typing-required)" + } + ] +} \ No newline at end of file diff --git a/linter-4.2/test_rules/rule147.ts b/linter-4.2/test_rules/rule147.ts new file mode 100644 index 000000000..cb9480d04 --- /dev/null +++ b/linter-4.2/test_rules/rule147.ts @@ -0,0 +1,7 @@ + // app.ets + export class C { + // ... + } + + // lib.ts + import { C } from "app" diff --git a/linter-4.2/test_rules/rule147.ts.autofix.json b/linter-4.2/test_rules/rule147.ts.autofix.json new file mode 100644 index 000000000..819d36d95 --- /dev/null +++ b/linter-4.2/test_rules/rule147.ts.autofix.json @@ -0,0 +1,34 @@ +{ + "copyright": [ + "Copyright (c) 2023-2023 Huawei Device Co., Ltd.", + "Licensed under the Apache License, Version 2.0 (the 'License');", + "you may not use this file except in compliance with the License.", + "You may obtain a copy of the License at", + "", + "http://www.apache.org/licenses/LICENSE-2.0", + "", + "Unless required by applicable law or agreed to in writing, software", + "distributed under the License is distributed on an 'AS IS' BASIS,", + "WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.", + "See the License for the specific language governing permissions and", + "limitations under the License." + ], + "nodes": [ + { + "line": 7, + "column": 5, + "problem": "ImportAfterStatement", + "autofixable": false, + "suggest": "", + "rule": "\"import\" statements after other statements are not allowed (arkts-no-misplaced-imports)" + }, + { + "line": 7, + "column": 14, + "problem": "DeclWithDuplicateName", + "autofixable": false, + "suggest": "", + "rule": "Use unique names for types and namespaces. (arkts-unique-names)" + } + ] +} \ No newline at end of file diff --git a/linter-4.2/test_rules/rule147.ts.relax.json b/linter-4.2/test_rules/rule147.ts.relax.json new file mode 100644 index 000000000..ad3d2d80e --- /dev/null +++ b/linter-4.2/test_rules/rule147.ts.relax.json @@ -0,0 +1,10 @@ +{ + "nodes": [ + { + "line": 7, + "column": 5, + "problem": "ImportAfterStatement", + "rule": "\"import\" statements after other statements are not allowed (arkts-no-misplaced-imports)" + } + ] +} \ No newline at end of file diff --git a/linter-4.2/test_rules/rule147.ts.strict.json b/linter-4.2/test_rules/rule147.ts.strict.json new file mode 100644 index 000000000..99874461d --- /dev/null +++ b/linter-4.2/test_rules/rule147.ts.strict.json @@ -0,0 +1,32 @@ +{ + "copyright": [ + "Copyright (c) 2023-2023 Huawei Device Co., Ltd.", + "Licensed under the Apache License, Version 2.0 (the 'License');", + "you may not use this file except in compliance with the License.", + "You may obtain a copy of the License at", + "", + "http://www.apache.org/licenses/LICENSE-2.0", + "", + "Unless required by applicable law or agreed to in writing, software", + "distributed under the License is distributed on an 'AS IS' BASIS,", + "WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.", + "See the License for the specific language governing permissions and", + "limitations under the License." + ], + "nodes": [ + { + "line": 7, + "column": 5, + "problem": "ImportAfterStatement", + "suggest": "", + "rule": "\"import\" statements after other statements are not allowed (arkts-no-misplaced-imports)" + }, + { + "line": 7, + "column": 14, + "problem": "DeclWithDuplicateName", + "suggest": "", + "rule": "Use unique names for types and namespaces. (arkts-unique-names)" + } + ] +} \ No newline at end of file diff --git a/linter-4.2/test_rules/rule148.ts b/linter-4.2/test_rules/rule148.ts new file mode 100644 index 000000000..1266c4059 --- /dev/null +++ b/linter-4.2/test_rules/rule148.ts @@ -0,0 +1,7 @@ +function classDecorator(x: any, y: any): void { + // +} + +@classDecorator +class BugReport { +} \ No newline at end of file diff --git a/linter-4.2/test_rules/rule148.ts.autofix.json b/linter-4.2/test_rules/rule148.ts.autofix.json new file mode 100644 index 000000000..5c410df05 --- /dev/null +++ b/linter-4.2/test_rules/rule148.ts.autofix.json @@ -0,0 +1,27 @@ +{ + "nodes": [ + { + "line": 1, + "column": 28, + "problem": "AnyType", + "autofixable": false, + "suggest": "", + "rule": "Use explicit types instead of \"any\", \"unknown\" (arkts-no-any-unknown)" + }, + { + "line": 1, + "column": 36, + "problem": "AnyType", + "autofixable": false, + "suggest": "", + "rule": "Use explicit types instead of \"any\", \"unknown\" (arkts-no-any-unknown)" + }, + { + "line": 5, + "column": 1, + "problem": "UnsupportedDecorators", + "autofixable": false, + "rule": "No decorators except ArkUI decorators are currently allowed (arkts-no-decorators-except-arkui)" + } + ] +} \ No newline at end of file diff --git a/linter-4.2/test_rules/rule148.ts.relax.json b/linter-4.2/test_rules/rule148.ts.relax.json new file mode 100644 index 000000000..b2cd5b221 --- /dev/null +++ b/linter-4.2/test_rules/rule148.ts.relax.json @@ -0,0 +1,24 @@ +{ + "nodes": [ + { + "line": 1, + "column": 28, + "problem": "AnyType", + "suggest": "", + "rule": "Use explicit types instead of \"any\", \"unknown\" (arkts-no-any-unknown)" + }, + { + "line": 1, + "column": 36, + "problem": "AnyType", + "suggest": "", + "rule": "Use explicit types instead of \"any\", \"unknown\" (arkts-no-any-unknown)" + }, + { + "line": 5, + "column": 1, + "problem": "UnsupportedDecorators", + "rule": "No decorators except ArkUI decorators are currently allowed (arkts-no-decorators-except-arkui)" + } + ] +} \ No newline at end of file diff --git a/linter-4.2/test_rules/rule148.ts.strict.json b/linter-4.2/test_rules/rule148.ts.strict.json new file mode 100644 index 000000000..b2cd5b221 --- /dev/null +++ b/linter-4.2/test_rules/rule148.ts.strict.json @@ -0,0 +1,24 @@ +{ + "nodes": [ + { + "line": 1, + "column": 28, + "problem": "AnyType", + "suggest": "", + "rule": "Use explicit types instead of \"any\", \"unknown\" (arkts-no-any-unknown)" + }, + { + "line": 1, + "column": 36, + "problem": "AnyType", + "suggest": "", + "rule": "Use explicit types instead of \"any\", \"unknown\" (arkts-no-any-unknown)" + }, + { + "line": 5, + "column": 1, + "problem": "UnsupportedDecorators", + "rule": "No decorators except ArkUI decorators are currently allowed (arkts-no-decorators-except-arkui)" + } + ] +} \ No newline at end of file diff --git a/linter-4.2/test_rules/rule15.ts b/linter-4.2/test_rules/rule15.ts new file mode 100644 index 000000000..5a10c4869 --- /dev/null +++ b/linter-4.2/test_rules/rule15.ts @@ -0,0 +1,21 @@ +class SomeObject {} + +type SomeConstructor = { + new (s: string): SomeObject +} + +function fn(ctor: SomeConstructor) { + return new ctor("hello") +} + + +class SomeObject2 { + public f: string + constructor (s: string) { + this.f = s + } +} + +function foo(s: string): SomeObject { + return new SomeObject2(s) +} \ No newline at end of file diff --git a/linter-4.2/test_rules/rule15.ts.autofix.json b/linter-4.2/test_rules/rule15.ts.autofix.json new file mode 100644 index 000000000..84c2e5922 --- /dev/null +++ b/linter-4.2/test_rules/rule15.ts.autofix.json @@ -0,0 +1,20 @@ +{ + "nodes": [ + { + "line": 3, + "column": 24, + "problem": "ObjectTypeLiteral", + "autofixable": false, + "suggest": "", + "rule": "Object literals cannot be used as type declarations (arkts-no-obj-literals-as-types)" + }, + { + "line": 4, + "column": 5, + "problem": "ConstructorType", + "autofixable": false, + "suggest": "", + "rule": "Use \"class\" instead of a type with constructor signature (arkts-no-ctor-signatures-type)" + } + ] +} \ No newline at end of file diff --git a/linter-4.2/test_rules/rule15.ts.relax.json b/linter-4.2/test_rules/rule15.ts.relax.json new file mode 100644 index 000000000..523bca27d --- /dev/null +++ b/linter-4.2/test_rules/rule15.ts.relax.json @@ -0,0 +1,18 @@ +{ + "nodes": [ + { + "line": 3, + "column": 24, + "problem": "ObjectTypeLiteral", + "suggest": "", + "rule": "Object literals cannot be used as type declarations (arkts-no-obj-literals-as-types)" + }, + { + "line": 4, + "column": 5, + "problem": "ConstructorType", + "suggest": "", + "rule": "Use \"class\" instead of a type with constructor signature (arkts-no-ctor-signatures-type)" + } + ] +} \ No newline at end of file diff --git a/linter-4.2/test_rules/rule15.ts.strict.json b/linter-4.2/test_rules/rule15.ts.strict.json new file mode 100644 index 000000000..523bca27d --- /dev/null +++ b/linter-4.2/test_rules/rule15.ts.strict.json @@ -0,0 +1,18 @@ +{ + "nodes": [ + { + "line": 3, + "column": 24, + "problem": "ObjectTypeLiteral", + "suggest": "", + "rule": "Object literals cannot be used as type declarations (arkts-no-obj-literals-as-types)" + }, + { + "line": 4, + "column": 5, + "problem": "ConstructorType", + "suggest": "", + "rule": "Use \"class\" instead of a type with constructor signature (arkts-no-ctor-signatures-type)" + } + ] +} \ No newline at end of file diff --git a/linter-4.2/test_rules/rule17.ts b/linter-4.2/test_rules/rule17.ts new file mode 100644 index 000000000..ed3d09638 --- /dev/null +++ b/linter-4.2/test_rules/rule17.ts @@ -0,0 +1,17 @@ +interface StringArray { + [index: number]: string +} + +function getStringArray() : StringArray { + return ["a", "b", "c"] +} + +const myArray: StringArray = getStringArray() +const secondItem = myArray[1] + +class Y { + public f: string[] = [] +} + +let myArray2: Y = new Y() +const secondItem2 = myArray2.f[1] \ No newline at end of file diff --git a/linter-4.2/test_rules/rule17.ts.autofix.json b/linter-4.2/test_rules/rule17.ts.autofix.json new file mode 100644 index 000000000..dcd0bb1a1 --- /dev/null +++ b/linter-4.2/test_rules/rule17.ts.autofix.json @@ -0,0 +1,34 @@ +{ + "copyright": [ + "Copyright (c) 2023-2023 Huawei Device Co., Ltd.", + "Licensed under the Apache License, Version 2.0 (the 'License');", + "you may not use this file except in compliance with the License.", + "You may obtain a copy of the License at", + "", + "http://www.apache.org/licenses/LICENSE-2.0", + "", + "Unless required by applicable law or agreed to in writing, software", + "distributed under the License is distributed on an 'AS IS' BASIS,", + "WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.", + "See the License for the specific language governing permissions and", + "limitations under the License." + ], + "nodes": [ + { + "line": 2, + "column": 5, + "problem": "IndexMember", + "autofixable": false, + "suggest": "", + "rule": "Indexed signatures are not supported (arkts-no-indexed-signatures)" + }, + { + "line": 10, + "column": 20, + "problem": "PropertyAccessByIndex", + "autofixable": true, + "suggest": "", + "rule": "Indexed access is not supported for fields (arkts-no-props-by-index)" + } + ] +} \ No newline at end of file diff --git a/linter-4.2/test_rules/rule17.ts.relax.json b/linter-4.2/test_rules/rule17.ts.relax.json new file mode 100644 index 000000000..43a5aef4c --- /dev/null +++ b/linter-4.2/test_rules/rule17.ts.relax.json @@ -0,0 +1,11 @@ +{ + "nodes": [ + { + "line": 2, + "column": 5, + "problem": "IndexMember", + "suggest": "", + "rule": "Indexed signatures are not supported (arkts-no-indexed-signatures)" + } + ] +} \ No newline at end of file diff --git a/linter-4.2/test_rules/rule17.ts.strict.json b/linter-4.2/test_rules/rule17.ts.strict.json new file mode 100644 index 000000000..b998aa81e --- /dev/null +++ b/linter-4.2/test_rules/rule17.ts.strict.json @@ -0,0 +1,18 @@ +{ + "nodes": [ + { + "line": 2, + "column": 5, + "problem": "IndexMember", + "suggest": "", + "rule": "Indexed signatures are not supported (arkts-no-indexed-signatures)" + }, + { + "line": 10, + "column": 20, + "problem": "PropertyAccessByIndex", + "suggest": "", + "rule": "Indexed access is not supported for fields (arkts-no-props-by-index)" + } + ] +} \ No newline at end of file diff --git a/linter-4.2/test_rules/rule19.ts b/linter-4.2/test_rules/rule19.ts new file mode 100644 index 000000000..e3ec4340c --- /dev/null +++ b/linter-4.2/test_rules/rule19.ts @@ -0,0 +1,13 @@ +interface Identity { + id: number + name: string +} + +interface Contact { + email: string + phone: string +} + +type Employee = Identity & Contact + +interface Employee2 extends Identity, Contact {} \ No newline at end of file diff --git a/linter-4.2/test_rules/rule19.ts.autofix.json b/linter-4.2/test_rules/rule19.ts.autofix.json new file mode 100644 index 000000000..2a5b7dbc5 --- /dev/null +++ b/linter-4.2/test_rules/rule19.ts.autofix.json @@ -0,0 +1,12 @@ +{ + "nodes": [ + { + "line": 11, + "column": 17, + "problem": "IntersectionType", + "autofixable": false, + "suggest": "", + "rule": "Use inheritance instead of intersection types (arkts-no-intersection-types)" + } + ] +} \ No newline at end of file diff --git a/linter-4.2/test_rules/rule19.ts.relax.json b/linter-4.2/test_rules/rule19.ts.relax.json new file mode 100644 index 000000000..a3023753d --- /dev/null +++ b/linter-4.2/test_rules/rule19.ts.relax.json @@ -0,0 +1,11 @@ +{ + "nodes": [ + { + "line": 11, + "column": 17, + "problem": "IntersectionType", + "suggest": "", + "rule": "Use inheritance instead of intersection types (arkts-no-intersection-types)" + } + ] +} \ No newline at end of file diff --git a/linter-4.2/test_rules/rule19.ts.strict.json b/linter-4.2/test_rules/rule19.ts.strict.json new file mode 100644 index 000000000..a3023753d --- /dev/null +++ b/linter-4.2/test_rules/rule19.ts.strict.json @@ -0,0 +1,11 @@ +{ + "nodes": [ + { + "line": 11, + "column": 17, + "problem": "IntersectionType", + "suggest": "", + "rule": "Use inheritance instead of intersection types (arkts-no-intersection-types)" + } + ] +} \ No newline at end of file diff --git a/linter-4.2/test_rules/rule2.ts b/linter-4.2/test_rules/rule2.ts new file mode 100644 index 000000000..7d5ced644 --- /dev/null +++ b/linter-4.2/test_rules/rule2.ts @@ -0,0 +1,11 @@ + +const sym = Symbol() + +let o = { + [sym]: "value" +} + +class SomeClass { + public someProperty : string = "" +} +let z = new SomeClass() \ No newline at end of file diff --git a/linter-4.2/test_rules/rule2.ts.autofix.json b/linter-4.2/test_rules/rule2.ts.autofix.json new file mode 100644 index 000000000..715657397 --- /dev/null +++ b/linter-4.2/test_rules/rule2.ts.autofix.json @@ -0,0 +1,28 @@ +{ + "nodes": [ + { + "line": 2, + "column": 13, + "problem": "SymbolType", + "autofixable": false, + "suggest": "", + "rule": "\"Symbol()\" API is not supported (arkts-no-symbol)" + }, + { + "line": 4, + "column": 9, + "problem": "ObjectLiteralNoContextType", + "autofixable": false, + "suggest": "", + "rule": "Object literal must correspond to some explicitly declared class or interface (arkts-no-untyped-obj-literals)" + }, + { + "line": 5, + "column": 4, + "problem": "ComputedPropertyName", + "autofixable": false, + "suggest": "", + "rule": "Objects with property names that are not identifiers are not supported (arkts-identifiers-as-prop-names)" + } + ] +} \ No newline at end of file diff --git a/linter-4.2/test_rules/rule2.ts.relax.json b/linter-4.2/test_rules/rule2.ts.relax.json new file mode 100644 index 000000000..8d2f8bc1b --- /dev/null +++ b/linter-4.2/test_rules/rule2.ts.relax.json @@ -0,0 +1,25 @@ +{ + "nodes": [ + { + "line": 2, + "column": 13, + "problem": "SymbolType", + "suggest": "", + "rule": "\"Symbol()\" API is not supported (arkts-no-symbol)" + }, + { + "line": 4, + "column": 9, + "problem": "ObjectLiteralNoContextType", + "suggest": "", + "rule": "Object literal must correspond to some explicitly declared class or interface (arkts-no-untyped-obj-literals)" + }, + { + "line": 5, + "column": 4, + "problem": "ComputedPropertyName", + "suggest": "", + "rule": "Objects with property names that are not identifiers are not supported (arkts-identifiers-as-prop-names)" + } + ] +} \ No newline at end of file diff --git a/linter-4.2/test_rules/rule2.ts.strict.json b/linter-4.2/test_rules/rule2.ts.strict.json new file mode 100644 index 000000000..8d2f8bc1b --- /dev/null +++ b/linter-4.2/test_rules/rule2.ts.strict.json @@ -0,0 +1,25 @@ +{ + "nodes": [ + { + "line": 2, + "column": 13, + "problem": "SymbolType", + "suggest": "", + "rule": "\"Symbol()\" API is not supported (arkts-no-symbol)" + }, + { + "line": 4, + "column": 9, + "problem": "ObjectLiteralNoContextType", + "suggest": "", + "rule": "Object literal must correspond to some explicitly declared class or interface (arkts-no-untyped-obj-literals)" + }, + { + "line": 5, + "column": 4, + "problem": "ComputedPropertyName", + "suggest": "", + "rule": "Objects with property names that are not identifiers are not supported (arkts-identifiers-as-prop-names)" + } + ] +} \ No newline at end of file diff --git a/linter-4.2/test_rules/rule21.ts b/linter-4.2/test_rules/rule21.ts new file mode 100644 index 000000000..aae13a788 --- /dev/null +++ b/linter-4.2/test_rules/rule21.ts @@ -0,0 +1,23 @@ +interface ListItem { + getHead(): this +} + +class C { + n: number = 0 + + m(c: this) { + console.log(c) + } +} + +interface ListItem2 { + getHead(): ListItem +} + +class D { + n: number = 0 + + m(c: D) { + console.log(c) + } +} \ No newline at end of file diff --git a/linter-4.2/test_rules/rule21.ts.autofix.json b/linter-4.2/test_rules/rule21.ts.autofix.json new file mode 100644 index 000000000..26da216ed --- /dev/null +++ b/linter-4.2/test_rules/rule21.ts.autofix.json @@ -0,0 +1,20 @@ +{ + "nodes": [ + { + "line": 2, + "column": 16, + "problem": "ThisType", + "autofixable": false, + "suggest": "", + "rule": "Type notation using \"this\" is not supported (arkts-no-typing-with-this)" + }, + { + "line": 8, + "column": 10, + "problem": "ThisType", + "autofixable": false, + "suggest": "", + "rule": "Type notation using \"this\" is not supported (arkts-no-typing-with-this)" + } + ] +} \ No newline at end of file diff --git a/linter-4.2/test_rules/rule21.ts.relax.json b/linter-4.2/test_rules/rule21.ts.relax.json new file mode 100644 index 000000000..efb1a7a16 --- /dev/null +++ b/linter-4.2/test_rules/rule21.ts.relax.json @@ -0,0 +1,18 @@ +{ + "nodes": [ + { + "line": 2, + "column": 16, + "problem": "ThisType", + "suggest": "", + "rule": "Type notation using \"this\" is not supported (arkts-no-typing-with-this)" + }, + { + "line": 8, + "column": 10, + "problem": "ThisType", + "suggest": "", + "rule": "Type notation using \"this\" is not supported (arkts-no-typing-with-this)" + } + ] +} \ No newline at end of file diff --git a/linter-4.2/test_rules/rule21.ts.strict.json b/linter-4.2/test_rules/rule21.ts.strict.json new file mode 100644 index 000000000..efb1a7a16 --- /dev/null +++ b/linter-4.2/test_rules/rule21.ts.strict.json @@ -0,0 +1,18 @@ +{ + "nodes": [ + { + "line": 2, + "column": 16, + "problem": "ThisType", + "suggest": "", + "rule": "Type notation using \"this\" is not supported (arkts-no-typing-with-this)" + }, + { + "line": 8, + "column": 10, + "problem": "ThisType", + "suggest": "", + "rule": "Type notation using \"this\" is not supported (arkts-no-typing-with-this)" + } + ] +} \ No newline at end of file diff --git a/linter-4.2/test_rules/rule22.ts b/linter-4.2/test_rules/rule22.ts new file mode 100644 index 000000000..fede281ba --- /dev/null +++ b/linter-4.2/test_rules/rule22.ts @@ -0,0 +1,7 @@ +type X = T extends number ? T : never + +type Y = T extends Array ? Item : never + +type X1 = T +type X2 = Object +type YI> = Item \ No newline at end of file diff --git a/linter-4.2/test_rules/rule22.ts.autofix.json b/linter-4.2/test_rules/rule22.ts.autofix.json new file mode 100644 index 000000000..2493216ba --- /dev/null +++ b/linter-4.2/test_rules/rule22.ts.autofix.json @@ -0,0 +1,20 @@ +{ + "nodes": [ + { + "line": 1, + "column": 13, + "problem": "ConditionalType", + "autofixable": false, + "suggest": "", + "rule": "Conditional types are not supported (arkts-no-conditional-types)" + }, + { + "line": 3, + "column": 13, + "problem": "ConditionalType", + "autofixable": false, + "suggest": "", + "rule": "Conditional types are not supported (arkts-no-conditional-types)" + } + ] +} diff --git a/linter-4.2/test_rules/rule22.ts.relax.json b/linter-4.2/test_rules/rule22.ts.relax.json new file mode 100644 index 000000000..4e1ebe000 --- /dev/null +++ b/linter-4.2/test_rules/rule22.ts.relax.json @@ -0,0 +1,18 @@ +{ + "nodes": [ + { + "line": 1, + "column": 13, + "problem": "ConditionalType", + "suggest": "", + "rule": "Conditional types are not supported (arkts-no-conditional-types)" + }, + { + "line": 3, + "column": 13, + "problem": "ConditionalType", + "suggest": "", + "rule": "Conditional types are not supported (arkts-no-conditional-types)" + } + ] +} diff --git a/linter-4.2/test_rules/rule22.ts.strict.json b/linter-4.2/test_rules/rule22.ts.strict.json new file mode 100644 index 000000000..4e1ebe000 --- /dev/null +++ b/linter-4.2/test_rules/rule22.ts.strict.json @@ -0,0 +1,18 @@ +{ + "nodes": [ + { + "line": 1, + "column": 13, + "problem": "ConditionalType", + "suggest": "", + "rule": "Conditional types are not supported (arkts-no-conditional-types)" + }, + { + "line": 3, + "column": 13, + "problem": "ConditionalType", + "suggest": "", + "rule": "Conditional types are not supported (arkts-no-conditional-types)" + } + ] +} diff --git a/linter-4.2/test_rules/rule25.ts b/linter-4.2/test_rules/rule25.ts new file mode 100644 index 000000000..a485b8eb2 --- /dev/null +++ b/linter-4.2/test_rules/rule25.ts @@ -0,0 +1,31 @@ +class Person { + constructor( + protected ssn: string, + private firstName: string, + private lastName: string + ) { + this.ssn = ssn + this.firstName = firstName + this.lastName = lastName + } + + getFullName(): string { + return this.firstName + " " + this.lastName + } +} + +class Person2{ + protected ssn: string + private firstName: string + private lastName: string + + constructor(ssn: string, firstName: string, lastName: string) { + this.ssn = ssn + this.firstName = firstName + this.lastName = lastName + } + + getFullName(): string { + return this.firstName + " " + this.lastName + } +} \ No newline at end of file diff --git a/linter-4.2/test_rules/rule25.ts.autofix.json b/linter-4.2/test_rules/rule25.ts.autofix.json new file mode 100644 index 000000000..4f15af43d --- /dev/null +++ b/linter-4.2/test_rules/rule25.ts.autofix.json @@ -0,0 +1,28 @@ +{ + "nodes": [ + { + "line": 3, + "column": 9, + "problem": "ParameterProperties", + "autofixable": false, + "suggest": "", + "rule": "Declaring fields in \"constructor\" is not supported (arkts-no-ctor-prop-decls)" + }, + { + "line": 4, + "column": 9, + "problem": "ParameterProperties", + "autofixable": false, + "suggest": "", + "rule": "Declaring fields in \"constructor\" is not supported (arkts-no-ctor-prop-decls)" + }, + { + "line": 5, + "column": 9, + "problem": "ParameterProperties", + "autofixable": false, + "suggest": "", + "rule": "Declaring fields in \"constructor\" is not supported (arkts-no-ctor-prop-decls)" + } + ] +} \ No newline at end of file diff --git a/linter-4.2/test_rules/rule25.ts.relax.json b/linter-4.2/test_rules/rule25.ts.relax.json new file mode 100644 index 000000000..13f13363f --- /dev/null +++ b/linter-4.2/test_rules/rule25.ts.relax.json @@ -0,0 +1,3 @@ +{ + "nodes": [] +} \ No newline at end of file diff --git a/linter-4.2/test_rules/rule25.ts.strict.json b/linter-4.2/test_rules/rule25.ts.strict.json new file mode 100644 index 000000000..ec5820fcb --- /dev/null +++ b/linter-4.2/test_rules/rule25.ts.strict.json @@ -0,0 +1,25 @@ +{ + "nodes": [ + { + "line": 3, + "column": 9, + "problem": "ParameterProperties", + "suggest": "", + "rule": "Declaring fields in \"constructor\" is not supported (arkts-no-ctor-prop-decls)" + }, + { + "line": 4, + "column": 9, + "problem": "ParameterProperties", + "suggest": "", + "rule": "Declaring fields in \"constructor\" is not supported (arkts-no-ctor-prop-decls)" + }, + { + "line": 5, + "column": 9, + "problem": "ParameterProperties", + "suggest": "", + "rule": "Declaring fields in \"constructor\" is not supported (arkts-no-ctor-prop-decls)" + } + ] +} \ No newline at end of file diff --git a/linter-4.2/test_rules/rule27.ts b/linter-4.2/test_rules/rule27.ts new file mode 100644 index 000000000..b9c737db9 --- /dev/null +++ b/linter-4.2/test_rules/rule27.ts @@ -0,0 +1,15 @@ +interface I { + new (s: string): I +} + +function fn(i: I) { + return new i("hello") +} + +interface I2 { + create(s: string): I +} + +function foo(i: I2) { + return i.create("hello") +} \ No newline at end of file diff --git a/linter-4.2/test_rules/rule27.ts.autofix.json b/linter-4.2/test_rules/rule27.ts.autofix.json new file mode 100644 index 000000000..cddbb344b --- /dev/null +++ b/linter-4.2/test_rules/rule27.ts.autofix.json @@ -0,0 +1,12 @@ +{ + "nodes": [ + { + "line": 2, + "column": 5, + "problem": "ConstructorIface", + "autofixable": false, + "suggest": "", + "rule": "Construct signatures are not supported in interfaces (arkts-no-ctor-signatures-iface)" + } + ] +} \ No newline at end of file diff --git a/linter-4.2/test_rules/rule27.ts.relax.json b/linter-4.2/test_rules/rule27.ts.relax.json new file mode 100644 index 000000000..9086d3bbc --- /dev/null +++ b/linter-4.2/test_rules/rule27.ts.relax.json @@ -0,0 +1,11 @@ +{ + "nodes": [ + { + "line": 2, + "column": 5, + "problem": "ConstructorIface", + "suggest": "", + "rule": "Construct signatures are not supported in interfaces (arkts-no-ctor-signatures-iface)" + } + ] +} \ No newline at end of file diff --git a/linter-4.2/test_rules/rule27.ts.strict.json b/linter-4.2/test_rules/rule27.ts.strict.json new file mode 100644 index 000000000..9086d3bbc --- /dev/null +++ b/linter-4.2/test_rules/rule27.ts.strict.json @@ -0,0 +1,11 @@ +{ + "nodes": [ + { + "line": 2, + "column": 5, + "problem": "ConstructorIface", + "suggest": "", + "rule": "Construct signatures are not supported in interfaces (arkts-no-ctor-signatures-iface)" + } + ] +} \ No newline at end of file diff --git a/linter-4.2/test_rules/rule28.ts b/linter-4.2/test_rules/rule28.ts new file mode 100644 index 000000000..243f640fd --- /dev/null +++ b/linter-4.2/test_rules/rule28.ts @@ -0,0 +1,5 @@ +type Point = {x: number, y: number} +type N = Point["x"] // is equal to number + +class Point2 {x: number = 0; y: number = 0} +type N2 = number \ No newline at end of file diff --git a/linter-4.2/test_rules/rule28.ts.autofix.json b/linter-4.2/test_rules/rule28.ts.autofix.json new file mode 100644 index 000000000..8f3017832 --- /dev/null +++ b/linter-4.2/test_rules/rule28.ts.autofix.json @@ -0,0 +1,20 @@ +{ + "nodes": [ + { + "line": 1, + "column": 14, + "problem": "ObjectTypeLiteral", + "autofixable": false, + "suggest": "", + "rule": "Object literals cannot be used as type declarations (arkts-no-obj-literals-as-types)" + }, + { + "line": 2, + "column": 10, + "problem": "IndexedAccessType", + "autofixable": false, + "suggest": "", + "rule": "Indexed access types are not supported (arkts-no-aliases-by-index)" + } + ] +} \ No newline at end of file diff --git a/linter-4.2/test_rules/rule28.ts.relax.json b/linter-4.2/test_rules/rule28.ts.relax.json new file mode 100644 index 000000000..df9d49b8d --- /dev/null +++ b/linter-4.2/test_rules/rule28.ts.relax.json @@ -0,0 +1,18 @@ +{ + "nodes": [ + { + "line": 1, + "column": 14, + "problem": "ObjectTypeLiteral", + "suggest": "", + "rule": "Object literals cannot be used as type declarations (arkts-no-obj-literals-as-types)" + }, + { + "line": 2, + "column": 10, + "problem": "IndexedAccessType", + "suggest": "", + "rule": "Indexed access types are not supported (arkts-no-aliases-by-index)" + } + ] +} \ No newline at end of file diff --git a/linter-4.2/test_rules/rule28.ts.strict.json b/linter-4.2/test_rules/rule28.ts.strict.json new file mode 100644 index 000000000..df9d49b8d --- /dev/null +++ b/linter-4.2/test_rules/rule28.ts.strict.json @@ -0,0 +1,18 @@ +{ + "nodes": [ + { + "line": 1, + "column": 14, + "problem": "ObjectTypeLiteral", + "suggest": "", + "rule": "Object literals cannot be used as type declarations (arkts-no-obj-literals-as-types)" + }, + { + "line": 2, + "column": 10, + "problem": "IndexedAccessType", + "suggest": "", + "rule": "Indexed access types are not supported (arkts-no-aliases-by-index)" + } + ] +} \ No newline at end of file diff --git a/linter-4.2/test_rules/rule29.ts b/linter-4.2/test_rules/rule29.ts new file mode 100644 index 000000000..b476ec4e2 --- /dev/null +++ b/linter-4.2/test_rules/rule29.ts @@ -0,0 +1,7 @@ +class Point {x: number = 0; y: number = 0} +let p: Point = {x: 1, y: 2} +let x = p["x"] + +class Point2 {x: number = 0; y: number = 0} +let p2: Point2 = {x: 1, y: 2} +let x2 = p.x \ No newline at end of file diff --git a/linter-4.2/test_rules/rule29.ts.autofix.json b/linter-4.2/test_rules/rule29.ts.autofix.json new file mode 100644 index 000000000..7ce06f06c --- /dev/null +++ b/linter-4.2/test_rules/rule29.ts.autofix.json @@ -0,0 +1,26 @@ +{ + "copyright": [ + "Copyright (c) 2023-2023 Huawei Device Co., Ltd.", + "Licensed under the Apache License, Version 2.0 (the 'License');", + "you may not use this file except in compliance with the License.", + "You may obtain a copy of the License at", + "", + "http://www.apache.org/licenses/LICENSE-2.0", + "", + "Unless required by applicable law or agreed to in writing, software", + "distributed under the License is distributed on an 'AS IS' BASIS,", + "WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.", + "See the License for the specific language governing permissions and", + "limitations under the License." + ], + "nodes": [ + { + "line": 3, + "column": 9, + "problem": "PropertyAccessByIndex", + "autofixable": true, + "suggest": "", + "rule": "Indexed access is not supported for fields (arkts-no-props-by-index)" + } + ] +} \ No newline at end of file diff --git a/linter-4.2/test_rules/rule29.ts.relax.json b/linter-4.2/test_rules/rule29.ts.relax.json new file mode 100644 index 000000000..13f13363f --- /dev/null +++ b/linter-4.2/test_rules/rule29.ts.relax.json @@ -0,0 +1,3 @@ +{ + "nodes": [] +} \ No newline at end of file diff --git a/linter-4.2/test_rules/rule29.ts.strict.json b/linter-4.2/test_rules/rule29.ts.strict.json new file mode 100644 index 000000000..be0431cb9 --- /dev/null +++ b/linter-4.2/test_rules/rule29.ts.strict.json @@ -0,0 +1,11 @@ +{ + "nodes": [ + { + "line": 3, + "column": 9, + "problem": "PropertyAccessByIndex", + "suggest": "", + "rule": "Indexed access is not supported for fields (arkts-no-props-by-index)" + } + ] +} \ No newline at end of file diff --git a/linter-4.2/test_rules/rule3.ts b/linter-4.2/test_rules/rule3.ts new file mode 100644 index 000000000..d01c13ee3 --- /dev/null +++ b/linter-4.2/test_rules/rule3.ts @@ -0,0 +1,8 @@ + +class C { + #foo: number = 42 +} + +class X { + private foo: number = 42 +} \ No newline at end of file diff --git a/linter-4.2/test_rules/rule3.ts.autofix.json b/linter-4.2/test_rules/rule3.ts.autofix.json new file mode 100644 index 000000000..447f6a263 --- /dev/null +++ b/linter-4.2/test_rules/rule3.ts.autofix.json @@ -0,0 +1,12 @@ +{ + "nodes": [ + { + "line": 3, + "column": 5, + "problem": "PrivateIdentifier", + "autofixable": false, + "suggest": "", + "rule": "Private '#' identifiers are not supported (arkts-no-private-identifiers)" + } + ] +} \ No newline at end of file diff --git a/linter-4.2/test_rules/rule3.ts.relax.json b/linter-4.2/test_rules/rule3.ts.relax.json new file mode 100644 index 000000000..13f13363f --- /dev/null +++ b/linter-4.2/test_rules/rule3.ts.relax.json @@ -0,0 +1,3 @@ +{ + "nodes": [] +} \ No newline at end of file diff --git a/linter-4.2/test_rules/rule3.ts.strict.json b/linter-4.2/test_rules/rule3.ts.strict.json new file mode 100644 index 000000000..92ea8921f --- /dev/null +++ b/linter-4.2/test_rules/rule3.ts.strict.json @@ -0,0 +1,11 @@ +{ + "nodes": [ + { + "line": 3, + "column": 5, + "problem": "PrivateIdentifier", + "suggest": "", + "rule": "Private '#' identifiers are not supported (arkts-no-private-identifiers)" + } + ] +} \ No newline at end of file diff --git a/linter-4.2/test_rules/rule30.ts b/linter-4.2/test_rules/rule30.ts new file mode 100644 index 000000000..3204b6f83 --- /dev/null +++ b/linter-4.2/test_rules/rule30.ts @@ -0,0 +1,9 @@ +interface X { + f(): string +} + +interface Y { + f(): string +} + +type Z = X \ No newline at end of file diff --git a/linter-4.2/test_rules/rule30.ts.autofix.json b/linter-4.2/test_rules/rule30.ts.autofix.json new file mode 100644 index 000000000..13f13363f --- /dev/null +++ b/linter-4.2/test_rules/rule30.ts.autofix.json @@ -0,0 +1,3 @@ +{ + "nodes": [] +} \ No newline at end of file diff --git a/linter-4.2/test_rules/rule30.ts.relax.json b/linter-4.2/test_rules/rule30.ts.relax.json new file mode 100644 index 000000000..13f13363f --- /dev/null +++ b/linter-4.2/test_rules/rule30.ts.relax.json @@ -0,0 +1,3 @@ +{ + "nodes": [] +} \ No newline at end of file diff --git a/linter-4.2/test_rules/rule30.ts.strict.json b/linter-4.2/test_rules/rule30.ts.strict.json new file mode 100644 index 000000000..13f13363f --- /dev/null +++ b/linter-4.2/test_rules/rule30.ts.strict.json @@ -0,0 +1,3 @@ +{ + "nodes": [] +} \ No newline at end of file diff --git a/linter-4.2/test_rules/rule31.ts b/linter-4.2/test_rules/rule31.ts new file mode 100644 index 000000000..b939cad5b --- /dev/null +++ b/linter-4.2/test_rules/rule31.ts @@ -0,0 +1,24 @@ +class X { + public foo: number + + constructor() { + this.foo = 0 + } +} + +class Y { + public foo: number + + constructor() { + this.foo = 0 + } +} + +let x = new X() +let y = new Y() + +console.log("Assign X to Y") +y = x + +console.log("Assign Y to X") +x = y \ No newline at end of file diff --git a/linter-4.2/test_rules/rule31.ts.autofix.json b/linter-4.2/test_rules/rule31.ts.autofix.json new file mode 100644 index 000000000..93738805a --- /dev/null +++ b/linter-4.2/test_rules/rule31.ts.autofix.json @@ -0,0 +1,34 @@ +{ + "copyright": [ + "Copyright (c) 2023-2023 Huawei Device Co., Ltd.", + "Licensed under the Apache License, Version 2.0 (the 'License');", + "you may not use this file except in compliance with the License.", + "You may obtain a copy of the License at", + "", + "http://www.apache.org/licenses/LICENSE-2.0", + "", + "Unless required by applicable law or agreed to in writing, software", + "distributed under the License is distributed on an 'AS IS' BASIS,", + "WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.", + "See the License for the specific language governing permissions and", + "limitations under the License." + ], + "nodes": [ + { + "line": 21, + "column": 1, + "problem": "StructuralIdentity", + "autofixable": false, + "suggest": "", + "rule": "Structural typing is not supported (arkts-no-structural-typing)" + }, + { + "line": 24, + "column": 1, + "problem": "StructuralIdentity", + "autofixable": false, + "suggest": "", + "rule": "Structural typing is not supported (arkts-no-structural-typing)" + } + ] +} \ No newline at end of file diff --git a/linter-4.2/test_rules/rule31.ts.relax.json b/linter-4.2/test_rules/rule31.ts.relax.json new file mode 100644 index 000000000..278f67e07 --- /dev/null +++ b/linter-4.2/test_rules/rule31.ts.relax.json @@ -0,0 +1,32 @@ +{ + "copyright": [ + "Copyright (c) 2023-2023 Huawei Device Co., Ltd.", + "Licensed under the Apache License, Version 2.0 (the 'License');", + "you may not use this file except in compliance with the License.", + "You may obtain a copy of the License at", + "", + "http://www.apache.org/licenses/LICENSE-2.0", + "", + "Unless required by applicable law or agreed to in writing, software", + "distributed under the License is distributed on an 'AS IS' BASIS,", + "WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.", + "See the License for the specific language governing permissions and", + "limitations under the License." + ], + "nodes": [ + { + "line": 21, + "column": 1, + "problem": "StructuralIdentity", + "suggest": "", + "rule": "Structural typing is not supported (arkts-no-structural-typing)" + }, + { + "line": 24, + "column": 1, + "problem": "StructuralIdentity", + "suggest": "", + "rule": "Structural typing is not supported (arkts-no-structural-typing)" + } + ] +} \ No newline at end of file diff --git a/linter-4.2/test_rules/rule31.ts.strict.json b/linter-4.2/test_rules/rule31.ts.strict.json new file mode 100644 index 000000000..278f67e07 --- /dev/null +++ b/linter-4.2/test_rules/rule31.ts.strict.json @@ -0,0 +1,32 @@ +{ + "copyright": [ + "Copyright (c) 2023-2023 Huawei Device Co., Ltd.", + "Licensed under the Apache License, Version 2.0 (the 'License');", + "you may not use this file except in compliance with the License.", + "You may obtain a copy of the License at", + "", + "http://www.apache.org/licenses/LICENSE-2.0", + "", + "Unless required by applicable law or agreed to in writing, software", + "distributed under the License is distributed on an 'AS IS' BASIS,", + "WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.", + "See the License for the specific language governing permissions and", + "limitations under the License." + ], + "nodes": [ + { + "line": 21, + "column": 1, + "problem": "StructuralIdentity", + "suggest": "", + "rule": "Structural typing is not supported (arkts-no-structural-typing)" + }, + { + "line": 24, + "column": 1, + "problem": "StructuralIdentity", + "suggest": "", + "rule": "Structural typing is not supported (arkts-no-structural-typing)" + } + ] +} \ No newline at end of file diff --git a/linter-4.2/test_rules/rule32.ts b/linter-4.2/test_rules/rule32.ts new file mode 100644 index 000000000..24005d7aa --- /dev/null +++ b/linter-4.2/test_rules/rule32.ts @@ -0,0 +1,57 @@ +class X { + public foo: number + + constructor() { + this.foo = 0 + } +} + +class Y { + public foo: number + constructor() { + this.foo = 0 + } +} + +let x = new X() +let y = new Y() + +console.log("Assign X to Y") +y = x + +console.log("Assign Y to X") +x = y + + + + +interface Z { + foo: number + } + + // X implements interface Z, which makes relation between X and Y explicit. + class C implements Z { + public foo: number + + constructor() { + this.foo = 0 + } + } + + // Y implements interface Z, which makes relation between X and Y explicit. + class C2 implements Z { + public foo: number + + constructor() { + this.foo = 0 + } + } + + let x1: Z = new C() + let y1: Z = new C2() + + console.log("Assign X to Y") + y1 = x1 // ok, both are of the same type + + console.log("Assign Y to X") + x1 = y1 // ok, both are of the same type \ No newline at end of file diff --git a/linter-4.2/test_rules/rule32.ts.autofix.json b/linter-4.2/test_rules/rule32.ts.autofix.json new file mode 100644 index 000000000..a932e2c69 --- /dev/null +++ b/linter-4.2/test_rules/rule32.ts.autofix.json @@ -0,0 +1,34 @@ +{ + "copyright": [ + "Copyright (c) 2023-2023 Huawei Device Co., Ltd.", + "Licensed under the Apache License, Version 2.0 (the 'License');", + "you may not use this file except in compliance with the License.", + "You may obtain a copy of the License at", + "", + "http://www.apache.org/licenses/LICENSE-2.0", + "", + "Unless required by applicable law or agreed to in writing, software", + "distributed under the License is distributed on an 'AS IS' BASIS,", + "WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.", + "See the License for the specific language governing permissions and", + "limitations under the License." + ], + "nodes": [ + { + "line": 20, + "column": 1, + "problem": "StructuralIdentity", + "autofixable": false, + "suggest": "", + "rule": "Structural typing is not supported (arkts-no-structural-typing)" + }, + { + "line": 23, + "column": 1, + "problem": "StructuralIdentity", + "autofixable": false, + "suggest": "", + "rule": "Structural typing is not supported (arkts-no-structural-typing)" + } + ] +} \ No newline at end of file diff --git a/linter-4.2/test_rules/rule32.ts.relax.json b/linter-4.2/test_rules/rule32.ts.relax.json new file mode 100644 index 000000000..6446311e9 --- /dev/null +++ b/linter-4.2/test_rules/rule32.ts.relax.json @@ -0,0 +1,32 @@ +{ + "copyright": [ + "Copyright (c) 2023-2023 Huawei Device Co., Ltd.", + "Licensed under the Apache License, Version 2.0 (the 'License');", + "you may not use this file except in compliance with the License.", + "You may obtain a copy of the License at", + "", + "http://www.apache.org/licenses/LICENSE-2.0", + "", + "Unless required by applicable law or agreed to in writing, software", + "distributed under the License is distributed on an 'AS IS' BASIS,", + "WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.", + "See the License for the specific language governing permissions and", + "limitations under the License." + ], + "nodes": [ + { + "line": 20, + "column": 1, + "problem": "StructuralIdentity", + "suggest": "", + "rule": "Structural typing is not supported (arkts-no-structural-typing)" + }, + { + "line": 23, + "column": 1, + "problem": "StructuralIdentity", + "suggest": "", + "rule": "Structural typing is not supported (arkts-no-structural-typing)" + } + ] +} \ No newline at end of file diff --git a/linter-4.2/test_rules/rule32.ts.strict.json b/linter-4.2/test_rules/rule32.ts.strict.json new file mode 100644 index 000000000..6446311e9 --- /dev/null +++ b/linter-4.2/test_rules/rule32.ts.strict.json @@ -0,0 +1,32 @@ +{ + "copyright": [ + "Copyright (c) 2023-2023 Huawei Device Co., Ltd.", + "Licensed under the Apache License, Version 2.0 (the 'License');", + "you may not use this file except in compliance with the License.", + "You may obtain a copy of the License at", + "", + "http://www.apache.org/licenses/LICENSE-2.0", + "", + "Unless required by applicable law or agreed to in writing, software", + "distributed under the License is distributed on an 'AS IS' BASIS,", + "WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.", + "See the License for the specific language governing permissions and", + "limitations under the License." + ], + "nodes": [ + { + "line": 20, + "column": 1, + "problem": "StructuralIdentity", + "suggest": "", + "rule": "Structural typing is not supported (arkts-no-structural-typing)" + }, + { + "line": 23, + "column": 1, + "problem": "StructuralIdentity", + "suggest": "", + "rule": "Structural typing is not supported (arkts-no-structural-typing)" + } + ] +} \ No newline at end of file diff --git a/linter-4.2/test_rules/rule34.ts b/linter-4.2/test_rules/rule34.ts new file mode 100644 index 000000000..fc20b813f --- /dev/null +++ b/linter-4.2/test_rules/rule34.ts @@ -0,0 +1,13 @@ +function choose(x: T, y: T): T { + return Math.random() < 0.5 ? x : y +} + +let x = choose(10, 20) +let y = choose("10", 20) + +function greet(): T { + return "Hello" as T +} +let z = greet() + +let p = greet() \ No newline at end of file diff --git a/linter-4.2/test_rules/rule34.ts.autofix.json b/linter-4.2/test_rules/rule34.ts.autofix.json new file mode 100644 index 000000000..669ab4d6a --- /dev/null +++ b/linter-4.2/test_rules/rule34.ts.autofix.json @@ -0,0 +1,20 @@ +{ + "nodes": [ + { + "line": 11, + "column": 5, + "problem": "UnknownType", + "autofixable": false, + "suggest": "", + "rule": "Use explicit types instead of \"any\", \"unknown\" (arkts-no-any-unknown)" + }, + { + "line": 11, + "column": 9, + "problem": "GenericCallNoTypeArgs", + "autofixable": false, + "suggest": "", + "rule": "Type inference in case of generic function calls is limited (arkts-no-inferred-generic-params)" + } + ] +} \ No newline at end of file diff --git a/linter-4.2/test_rules/rule34.ts.relax.json b/linter-4.2/test_rules/rule34.ts.relax.json new file mode 100644 index 000000000..b5ec7e883 --- /dev/null +++ b/linter-4.2/test_rules/rule34.ts.relax.json @@ -0,0 +1,18 @@ +{ + "nodes": [ + { + "line": 11, + "column": 5, + "problem": "UnknownType", + "suggest": "", + "rule": "Use explicit types instead of \"any\", \"unknown\" (arkts-no-any-unknown)" + }, + { + "line": 11, + "column": 9, + "problem": "GenericCallNoTypeArgs", + "suggest": "", + "rule": "Type inference in case of generic function calls is limited (arkts-no-inferred-generic-params)" + } + ] +} \ No newline at end of file diff --git a/linter-4.2/test_rules/rule34.ts.strict.json b/linter-4.2/test_rules/rule34.ts.strict.json new file mode 100644 index 000000000..b5ec7e883 --- /dev/null +++ b/linter-4.2/test_rules/rule34.ts.strict.json @@ -0,0 +1,18 @@ +{ + "nodes": [ + { + "line": 11, + "column": 5, + "problem": "UnknownType", + "suggest": "", + "rule": "Use explicit types instead of \"any\", \"unknown\" (arkts-no-any-unknown)" + }, + { + "line": 11, + "column": 9, + "problem": "GenericCallNoTypeArgs", + "suggest": "", + "rule": "Type inference in case of generic function calls is limited (arkts-no-inferred-generic-params)" + } + ] +} \ No newline at end of file diff --git a/linter-4.2/test_rules/rule35.ts b/linter-4.2/test_rules/rule35.ts new file mode 100644 index 000000000..a93a28ef1 --- /dev/null +++ b/linter-4.2/test_rules/rule35.ts @@ -0,0 +1,31 @@ +class X { + public foo: number + private s: string + + constructor (f: number) { + this.foo = f + this.s = "" + } + + public say(): void { + console.log("X = ", this.foo) + } +} + +class Y { + public foo: number + + constructor (f: number) { + this.foo = f + } + public say(): void { + console.log("Y = ", this.foo) + } +} + +function bar(z: X): void { + z.say() +} + +bar(new X(1)) +bar(new Y(2) as X) \ No newline at end of file diff --git a/linter-4.2/test_rules/rule35.ts.autofix.json b/linter-4.2/test_rules/rule35.ts.autofix.json new file mode 100644 index 000000000..b58aa1b18 --- /dev/null +++ b/linter-4.2/test_rules/rule35.ts.autofix.json @@ -0,0 +1,26 @@ +{ + "copyright": [ + "Copyright (c) 2023-2023 Huawei Device Co., Ltd.", + "Licensed under the Apache License, Version 2.0 (the 'License');", + "you may not use this file except in compliance with the License.", + "You may obtain a copy of the License at", + "", + "http://www.apache.org/licenses/LICENSE-2.0", + "", + "Unless required by applicable law or agreed to in writing, software", + "distributed under the License is distributed on an 'AS IS' BASIS,", + "WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.", + "See the License for the specific language governing permissions and", + "limitations under the License." + ], + "nodes": [ + { + "line": 31, + "column": 5, + "problem": "StructuralIdentity", + "autofixable": false, + "suggest": "", + "rule": "Structural typing is not supported (arkts-no-structural-typing)" + } + ] +} \ No newline at end of file diff --git a/linter-4.2/test_rules/rule35.ts.relax.json b/linter-4.2/test_rules/rule35.ts.relax.json new file mode 100644 index 000000000..f2b48d95a --- /dev/null +++ b/linter-4.2/test_rules/rule35.ts.relax.json @@ -0,0 +1,25 @@ +{ + "copyright": [ + "Copyright (c) 2023-2023 Huawei Device Co., Ltd.", + "Licensed under the Apache License, Version 2.0 (the 'License');", + "you may not use this file except in compliance with the License.", + "You may obtain a copy of the License at", + "", + "http://www.apache.org/licenses/LICENSE-2.0", + "", + "Unless required by applicable law or agreed to in writing, software", + "distributed under the License is distributed on an 'AS IS' BASIS,", + "WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.", + "See the License for the specific language governing permissions and", + "limitations under the License." + ], + "nodes": [ + { + "line": 31, + "column": 5, + "problem": "StructuralIdentity", + "suggest": "", + "rule": "Structural typing is not supported (arkts-no-structural-typing)" + } + ] +} \ No newline at end of file diff --git a/linter-4.2/test_rules/rule35.ts.strict.json b/linter-4.2/test_rules/rule35.ts.strict.json new file mode 100644 index 000000000..f2b48d95a --- /dev/null +++ b/linter-4.2/test_rules/rule35.ts.strict.json @@ -0,0 +1,25 @@ +{ + "copyright": [ + "Copyright (c) 2023-2023 Huawei Device Co., Ltd.", + "Licensed under the Apache License, Version 2.0 (the 'License');", + "you may not use this file except in compliance with the License.", + "You may obtain a copy of the License at", + "", + "http://www.apache.org/licenses/LICENSE-2.0", + "", + "Unless required by applicable law or agreed to in writing, software", + "distributed under the License is distributed on an 'AS IS' BASIS,", + "WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.", + "See the License for the specific language governing permissions and", + "limitations under the License." + ], + "nodes": [ + { + "line": 31, + "column": 5, + "problem": "StructuralIdentity", + "suggest": "", + "rule": "Structural typing is not supported (arkts-no-structural-typing)" + } + ] +} \ No newline at end of file diff --git a/linter-4.2/test_rules/rule37.ts b/linter-4.2/test_rules/rule37.ts new file mode 100644 index 000000000..b39b996ca --- /dev/null +++ b/linter-4.2/test_rules/rule37.ts @@ -0,0 +1,3 @@ +let regex: RegExp = /bc*d/ + +let regex2: RegExp = new RegExp("/bc*d/") \ No newline at end of file diff --git a/linter-4.2/test_rules/rule37.ts.autofix.json b/linter-4.2/test_rules/rule37.ts.autofix.json new file mode 100644 index 000000000..b7626c51f --- /dev/null +++ b/linter-4.2/test_rules/rule37.ts.autofix.json @@ -0,0 +1,12 @@ +{ + "nodes": [ + { + "line": 1, + "column": 21, + "problem": "RegexLiteral", + "autofixable": false, + "suggest": "", + "rule": "RegExp literals are not supported (arkts-no-regexp-literals)" + } + ] +} \ No newline at end of file diff --git a/linter-4.2/test_rules/rule37.ts.relax.json b/linter-4.2/test_rules/rule37.ts.relax.json new file mode 100644 index 000000000..f4fac00b6 --- /dev/null +++ b/linter-4.2/test_rules/rule37.ts.relax.json @@ -0,0 +1,11 @@ +{ + "nodes": [ + { + "line": 1, + "column": 21, + "problem": "RegexLiteral", + "suggest": "", + "rule": "RegExp literals are not supported (arkts-no-regexp-literals)" + } + ] +} \ No newline at end of file diff --git a/linter-4.2/test_rules/rule37.ts.strict.json b/linter-4.2/test_rules/rule37.ts.strict.json new file mode 100644 index 000000000..f4fac00b6 --- /dev/null +++ b/linter-4.2/test_rules/rule37.ts.strict.json @@ -0,0 +1,11 @@ +{ + "nodes": [ + { + "line": 1, + "column": 21, + "problem": "RegexLiteral", + "suggest": "", + "rule": "RegExp literals are not supported (arkts-no-regexp-literals)" + } + ] +} \ No newline at end of file diff --git a/linter-4.2/test_rules/rule38.ts b/linter-4.2/test_rules/rule38.ts new file mode 100644 index 000000000..41be78fe3 --- /dev/null +++ b/linter-4.2/test_rules/rule38.ts @@ -0,0 +1,53 @@ +class C1 { + n: number = 0 + s: string = "" +} + +let o1: C1 = {n: 42, s: "foo"} +let o2: C1 = {n: 42, s: "foo"} +let o3: C1 = {n: 42, s: "foo"} + +let oo: C1[] = [{n: 1, s: "1"}, {n: 2, s: "2"}] + +class C2 { + s: string + constructor(s: string) { + this.s = "s =" + s + } +} +let o4 = new C2("foo") + +class C3 { + n: number = 0 + s: string = "" +} +let o5: C3 = {n: 42, s: "foo"} + +abstract class A {} +class C extends A {} +let o6: C = {} + +class C4 { + n: number = 0 + s: string = "" + f() { + console.log("Hello") + } +} +let o7 = new C4() +o7.n = 42 +o7.s = "foo" + +class Point { + x: number = 0 + y: number = 0 +} + +function id_x_y(o: Point): Point { + return o +} + +let p: Point = {x: 5, y: 10} +id_x_y(p) + +id_x_y({x: 5, y: 10}) \ No newline at end of file diff --git a/linter-4.2/test_rules/rule38.ts.autofix.json b/linter-4.2/test_rules/rule38.ts.autofix.json new file mode 100644 index 000000000..13f13363f --- /dev/null +++ b/linter-4.2/test_rules/rule38.ts.autofix.json @@ -0,0 +1,3 @@ +{ + "nodes": [] +} \ No newline at end of file diff --git a/linter-4.2/test_rules/rule38.ts.relax.json b/linter-4.2/test_rules/rule38.ts.relax.json new file mode 100644 index 000000000..13f13363f --- /dev/null +++ b/linter-4.2/test_rules/rule38.ts.relax.json @@ -0,0 +1,3 @@ +{ + "nodes": [] +} \ No newline at end of file diff --git a/linter-4.2/test_rules/rule38.ts.strict.json b/linter-4.2/test_rules/rule38.ts.strict.json new file mode 100644 index 000000000..13f13363f --- /dev/null +++ b/linter-4.2/test_rules/rule38.ts.strict.json @@ -0,0 +1,3 @@ +{ + "nodes": [] +} \ No newline at end of file diff --git a/linter-4.2/test_rules/rule4.ts b/linter-4.2/test_rules/rule4.ts new file mode 100644 index 000000000..269e702b5 --- /dev/null +++ b/linter-4.2/test_rules/rule4.ts @@ -0,0 +1,2 @@ +let X: string +type X = number[] \ No newline at end of file diff --git a/linter-4.2/test_rules/rule4.ts.autofix.json b/linter-4.2/test_rules/rule4.ts.autofix.json new file mode 100644 index 000000000..ba15a33cf --- /dev/null +++ b/linter-4.2/test_rules/rule4.ts.autofix.json @@ -0,0 +1,34 @@ +{ + "copyright": [ + "Copyright (c) 2023-2023 Huawei Device Co., Ltd.", + "Licensed under the Apache License, Version 2.0 (the 'License');", + "you may not use this file except in compliance with the License.", + "You may obtain a copy of the License at", + "", + "http://www.apache.org/licenses/LICENSE-2.0", + "", + "Unless required by applicable law or agreed to in writing, software", + "distributed under the License is distributed on an 'AS IS' BASIS,", + "WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.", + "See the License for the specific language governing permissions and", + "limitations under the License." + ], + "nodes": [ + { + "line": 1, + "column": 5, + "problem": "DeclWithDuplicateName", + "autofixable": false, + "suggest": "", + "rule": "Use unique names for types and namespaces. (arkts-unique-names)" + }, + { + "line": 2, + "column": 1, + "problem": "DeclWithDuplicateName", + "autofixable": false, + "suggest": "", + "rule": "Use unique names for types and namespaces. (arkts-unique-names)" + } + ] +} \ No newline at end of file diff --git a/linter-4.2/test_rules/rule4.ts.relax.json b/linter-4.2/test_rules/rule4.ts.relax.json new file mode 100644 index 000000000..13f13363f --- /dev/null +++ b/linter-4.2/test_rules/rule4.ts.relax.json @@ -0,0 +1,3 @@ +{ + "nodes": [] +} \ No newline at end of file diff --git a/linter-4.2/test_rules/rule4.ts.strict.json b/linter-4.2/test_rules/rule4.ts.strict.json new file mode 100644 index 000000000..9dda4cf21 --- /dev/null +++ b/linter-4.2/test_rules/rule4.ts.strict.json @@ -0,0 +1,32 @@ +{ + "copyright": [ + "Copyright (c) 2023-2023 Huawei Device Co., Ltd.", + "Licensed under the Apache License, Version 2.0 (the 'License');", + "you may not use this file except in compliance with the License.", + "You may obtain a copy of the License at", + "", + "http://www.apache.org/licenses/LICENSE-2.0", + "", + "Unless required by applicable law or agreed to in writing, software", + "distributed under the License is distributed on an 'AS IS' BASIS,", + "WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.", + "See the License for the specific language governing permissions and", + "limitations under the License." + ], + "nodes": [ + { + "line": 1, + "column": 5, + "problem": "DeclWithDuplicateName", + "suggest": "", + "rule": "Use unique names for types and namespaces. (arkts-unique-names)" + }, + { + "line": 2, + "column": 1, + "problem": "DeclWithDuplicateName", + "suggest": "", + "rule": "Use unique names for types and namespaces. (arkts-unique-names)" + } + ] +} \ No newline at end of file diff --git a/linter-4.2/test_rules/rule40.ts b/linter-4.2/test_rules/rule40.ts new file mode 100644 index 000000000..1d4ab0378 --- /dev/null +++ b/linter-4.2/test_rules/rule40.ts @@ -0,0 +1,15 @@ +let o: {x: number, y: number} = { + x: 2, + y: 3 +} + +type S = Set<{x: number, y: number}> + +class C { + x: number = 0 + y: number = 0 +} + +let c: C = {x: 2, y: 3} + +type t = Set \ No newline at end of file diff --git a/linter-4.2/test_rules/rule40.ts.autofix.json b/linter-4.2/test_rules/rule40.ts.autofix.json new file mode 100644 index 000000000..8acc6b2c9 --- /dev/null +++ b/linter-4.2/test_rules/rule40.ts.autofix.json @@ -0,0 +1,28 @@ +{ + "nodes": [ + { + "line": 1, + "column": 8, + "problem": "ObjectTypeLiteral", + "autofixable": false, + "suggest": "", + "rule": "Object literals cannot be used as type declarations (arkts-no-obj-literals-as-types)" + }, + { + "line": 1, + "column": 33, + "problem": "ObjectLiteralNoContextType", + "autofixable": false, + "suggest": "", + "rule": "Object literal must correspond to some explicitly declared class or interface (arkts-no-untyped-obj-literals)" + }, + { + "line": 6, + "column": 14, + "problem": "ObjectTypeLiteral", + "autofixable": false, + "suggest": "", + "rule": "Object literals cannot be used as type declarations (arkts-no-obj-literals-as-types)" + } + ] +} \ No newline at end of file diff --git a/linter-4.2/test_rules/rule40.ts.relax.json b/linter-4.2/test_rules/rule40.ts.relax.json new file mode 100644 index 000000000..77aeae718 --- /dev/null +++ b/linter-4.2/test_rules/rule40.ts.relax.json @@ -0,0 +1,25 @@ +{ + "nodes": [ + { + "line": 1, + "column": 8, + "problem": "ObjectTypeLiteral", + "suggest": "", + "rule": "Object literals cannot be used as type declarations (arkts-no-obj-literals-as-types)" + }, + { + "line": 1, + "column": 33, + "problem": "ObjectLiteralNoContextType", + "suggest": "", + "rule": "Object literal must correspond to some explicitly declared class or interface (arkts-no-untyped-obj-literals)" + }, + { + "line": 6, + "column": 14, + "problem": "ObjectTypeLiteral", + "suggest": "", + "rule": "Object literals cannot be used as type declarations (arkts-no-obj-literals-as-types)" + } + ] +} \ No newline at end of file diff --git a/linter-4.2/test_rules/rule40.ts.strict.json b/linter-4.2/test_rules/rule40.ts.strict.json new file mode 100644 index 000000000..77aeae718 --- /dev/null +++ b/linter-4.2/test_rules/rule40.ts.strict.json @@ -0,0 +1,25 @@ +{ + "nodes": [ + { + "line": 1, + "column": 8, + "problem": "ObjectTypeLiteral", + "suggest": "", + "rule": "Object literals cannot be used as type declarations (arkts-no-obj-literals-as-types)" + }, + { + "line": 1, + "column": 33, + "problem": "ObjectLiteralNoContextType", + "suggest": "", + "rule": "Object literal must correspond to some explicitly declared class or interface (arkts-no-untyped-obj-literals)" + }, + { + "line": 6, + "column": 14, + "problem": "ObjectTypeLiteral", + "suggest": "", + "rule": "Object literals cannot be used as type declarations (arkts-no-obj-literals-as-types)" + } + ] +} \ No newline at end of file diff --git a/linter-4.2/test_rules/rule43.ts b/linter-4.2/test_rules/rule43.ts new file mode 100644 index 000000000..c6b541f6c --- /dev/null +++ b/linter-4.2/test_rules/rule43.ts @@ -0,0 +1,9 @@ +let a = [{n: 1, s: "1"}, {n: 2, s : "2"}] + +class C { + n: number = 0 + s: string = "" +} + +let a1 = [{n: 1, s: "1"} as C, {n: 2, s : "2"} as C] +let a2: C[] = [{n: 1, s: "1"}, {n: 2, s : "2"}] \ No newline at end of file diff --git a/linter-4.2/test_rules/rule43.ts.autofix.json b/linter-4.2/test_rules/rule43.ts.autofix.json new file mode 100644 index 000000000..dd7966c87 --- /dev/null +++ b/linter-4.2/test_rules/rule43.ts.autofix.json @@ -0,0 +1,28 @@ +{ + "nodes": [ + { + "line": 1, + "column": 9, + "problem": "ArrayLiteralNoContextType", + "autofixable": false, + "suggest": "", + "rule": "Array literals must contain elements of only inferrable types (arkts-no-noninferrable-arr-literals)" + }, + { + "line": 1, + "column": 10, + "problem": "ObjectLiteralNoContextType", + "autofixable": false, + "suggest": "", + "rule": "Object literal must correspond to some explicitly declared class or interface (arkts-no-untyped-obj-literals)" + }, + { + "line": 1, + "column": 26, + "problem": "ObjectLiteralNoContextType", + "autofixable": false, + "suggest": "", + "rule": "Object literal must correspond to some explicitly declared class or interface (arkts-no-untyped-obj-literals)" + } + ] +} \ No newline at end of file diff --git a/linter-4.2/test_rules/rule43.ts.relax.json b/linter-4.2/test_rules/rule43.ts.relax.json new file mode 100644 index 000000000..07184c23a --- /dev/null +++ b/linter-4.2/test_rules/rule43.ts.relax.json @@ -0,0 +1,25 @@ +{ + "nodes": [ + { + "line": 1, + "column": 9, + "problem": "ArrayLiteralNoContextType", + "suggest": "", + "rule": "Array literals must contain elements of only inferrable types (arkts-no-noninferrable-arr-literals)" + }, + { + "line": 1, + "column": 10, + "problem": "ObjectLiteralNoContextType", + "suggest": "", + "rule": "Object literal must correspond to some explicitly declared class or interface (arkts-no-untyped-obj-literals)" + }, + { + "line": 1, + "column": 26, + "problem": "ObjectLiteralNoContextType", + "suggest": "", + "rule": "Object literal must correspond to some explicitly declared class or interface (arkts-no-untyped-obj-literals)" + } + ] +} \ No newline at end of file diff --git a/linter-4.2/test_rules/rule43.ts.strict.json b/linter-4.2/test_rules/rule43.ts.strict.json new file mode 100644 index 000000000..07184c23a --- /dev/null +++ b/linter-4.2/test_rules/rule43.ts.strict.json @@ -0,0 +1,25 @@ +{ + "nodes": [ + { + "line": 1, + "column": 9, + "problem": "ArrayLiteralNoContextType", + "suggest": "", + "rule": "Array literals must contain elements of only inferrable types (arkts-no-noninferrable-arr-literals)" + }, + { + "line": 1, + "column": 10, + "problem": "ObjectLiteralNoContextType", + "suggest": "", + "rule": "Object literal must correspond to some explicitly declared class or interface (arkts-no-untyped-obj-literals)" + }, + { + "line": 1, + "column": 26, + "problem": "ObjectLiteralNoContextType", + "suggest": "", + "rule": "Object literal must correspond to some explicitly declared class or interface (arkts-no-untyped-obj-literals)" + } + ] +} \ No newline at end of file diff --git a/linter-4.2/test_rules/rule45.ts b/linter-4.2/test_rules/rule45.ts new file mode 100644 index 000000000..8816b0021 --- /dev/null +++ b/linter-4.2/test_rules/rule45.ts @@ -0,0 +1,8 @@ + +let f = (s /* type any is assumed */) => { + console.log(s) +} + +let foo = (s: string) => { + console.log(s) +} diff --git a/linter-4.2/test_rules/rule45.ts.autofix.json b/linter-4.2/test_rules/rule45.ts.autofix.json new file mode 100644 index 000000000..b07ed33fd --- /dev/null +++ b/linter-4.2/test_rules/rule45.ts.autofix.json @@ -0,0 +1,12 @@ +{ + "nodes": [ + { + "line": 2, + "column": 10, + "problem": "AnyType", + "autofixable": false, + "suggest": "", + "rule": "Use explicit types instead of \"any\", \"unknown\" (arkts-no-any-unknown)" + } + ] +} \ No newline at end of file diff --git a/linter-4.2/test_rules/rule45.ts.relax.json b/linter-4.2/test_rules/rule45.ts.relax.json new file mode 100644 index 000000000..af6deaf3c --- /dev/null +++ b/linter-4.2/test_rules/rule45.ts.relax.json @@ -0,0 +1,11 @@ +{ + "nodes": [ + { + "line": 2, + "column": 10, + "problem": "AnyType", + "suggest": "", + "rule": "Use explicit types instead of \"any\", \"unknown\" (arkts-no-any-unknown)" + } + ] +} \ No newline at end of file diff --git a/linter-4.2/test_rules/rule45.ts.strict.json b/linter-4.2/test_rules/rule45.ts.strict.json new file mode 100644 index 000000000..af6deaf3c --- /dev/null +++ b/linter-4.2/test_rules/rule45.ts.strict.json @@ -0,0 +1,11 @@ +{ + "nodes": [ + { + "line": 2, + "column": 10, + "problem": "AnyType", + "suggest": "", + "rule": "Use explicit types instead of \"any\", \"unknown\" (arkts-no-any-unknown)" + } + ] +} \ No newline at end of file diff --git a/linter-4.2/test_rules/rule46.ts b/linter-4.2/test_rules/rule46.ts new file mode 100644 index 000000000..3032950f9 --- /dev/null +++ b/linter-4.2/test_rules/rule46.ts @@ -0,0 +1,7 @@ +let f = function (s: string) { + console.log(s) +} + +let foo = (s: string) => { + console.log(s) +} \ No newline at end of file diff --git a/linter-4.2/test_rules/rule46.ts.autofix.json b/linter-4.2/test_rules/rule46.ts.autofix.json new file mode 100644 index 000000000..c3b09f54a --- /dev/null +++ b/linter-4.2/test_rules/rule46.ts.autofix.json @@ -0,0 +1,19 @@ +{ + "nodes": [ + { + "line": 1, + "column": 9, + "problem": "FunctionExpression", + "autofixable": true, + "autofix": [ + { + "start": 8, + "end": 51, + "replacementText": "(s: string) => {\n console.log(s);\n}" + } + ], + "suggest": "", + "rule": "Use arrow functions instead of function expressions (arkts-no-func-expressions)" + } + ] +} \ No newline at end of file diff --git a/linter-4.2/test_rules/rule46.ts.relax.json b/linter-4.2/test_rules/rule46.ts.relax.json new file mode 100644 index 000000000..13f13363f --- /dev/null +++ b/linter-4.2/test_rules/rule46.ts.relax.json @@ -0,0 +1,3 @@ +{ + "nodes": [] +} \ No newline at end of file diff --git a/linter-4.2/test_rules/rule46.ts.strict.json b/linter-4.2/test_rules/rule46.ts.strict.json new file mode 100644 index 000000000..de176917c --- /dev/null +++ b/linter-4.2/test_rules/rule46.ts.strict.json @@ -0,0 +1,11 @@ +{ + "nodes": [ + { + "line": 1, + "column": 9, + "problem": "FunctionExpression", + "suggest": "", + "rule": "Use arrow functions instead of function expressions (arkts-no-func-expressions)" + } + ] +} \ No newline at end of file diff --git a/linter-4.2/test_rules/rule49.ts b/linter-4.2/test_rules/rule49.ts new file mode 100644 index 000000000..9510d5d91 --- /dev/null +++ b/linter-4.2/test_rules/rule49.ts @@ -0,0 +1,9 @@ +let generic_arrow_func = (x: T) => { return x } + +generic_arrow_func("string") + +function generic_func(x: T): T { + return x +} + +generic_func("string") \ No newline at end of file diff --git a/linter-4.2/test_rules/rule49.ts.autofix.json b/linter-4.2/test_rules/rule49.ts.autofix.json new file mode 100644 index 000000000..10a861657 --- /dev/null +++ b/linter-4.2/test_rules/rule49.ts.autofix.json @@ -0,0 +1,12 @@ +{ + "nodes": [ + { + "line": 1, + "column": 26, + "problem": "LambdaWithTypeParameters", + "autofixable": false, + "suggest": "", + "rule": "Use generic functions instead of generic arrow functions (arkts-no-generic-lambdas)" + } + ] +} \ No newline at end of file diff --git a/linter-4.2/test_rules/rule49.ts.relax.json b/linter-4.2/test_rules/rule49.ts.relax.json new file mode 100644 index 000000000..13f13363f --- /dev/null +++ b/linter-4.2/test_rules/rule49.ts.relax.json @@ -0,0 +1,3 @@ +{ + "nodes": [] +} \ No newline at end of file diff --git a/linter-4.2/test_rules/rule49.ts.strict.json b/linter-4.2/test_rules/rule49.ts.strict.json new file mode 100644 index 000000000..f2c3c0bfb --- /dev/null +++ b/linter-4.2/test_rules/rule49.ts.strict.json @@ -0,0 +1,11 @@ +{ + "nodes": [ + { + "line": 1, + "column": 26, + "problem": "LambdaWithTypeParameters", + "suggest": "", + "rule": "Use generic functions instead of generic arrow functions (arkts-no-generic-lambdas)" + } + ] +} \ No newline at end of file diff --git a/linter-4.2/test_rules/rule5.ts b/linter-4.2/test_rules/rule5.ts new file mode 100644 index 000000000..9fbf488e6 --- /dev/null +++ b/linter-4.2/test_rules/rule5.ts @@ -0,0 +1,19 @@ + +function f(shouldInitialize: boolean) { + if (shouldInitialize) { + var x = 10 + } + return x +} + +console.log(f(true)) +console.log(f(false)) + +let upper_let = 0 +{ + var scoped_var = 0 + let scoped_let = 0 + upper_let = 5 +} +scoped_var = 5 +scoped_let = 5 \ No newline at end of file diff --git a/linter-4.2/test_rules/rule5.ts.autofix.json b/linter-4.2/test_rules/rule5.ts.autofix.json new file mode 100644 index 000000000..a69b62867 --- /dev/null +++ b/linter-4.2/test_rules/rule5.ts.autofix.json @@ -0,0 +1,28 @@ +{ + "nodes": [ + { + "line": 4, + "column": 8, + "problem": "VarDeclaration", + "autofixable": false, + "suggest": "", + "rule": "Use \"let\" instead of \"var\" (arkts-no-var)" + }, + { + "line": 14, + "column": 5, + "problem": "VarDeclaration", + "autofixable": false, + "suggest": "", + "rule": "Use \"let\" instead of \"var\" (arkts-no-var)" + }, + { + "line": 6, + "column": 12, + "problem": "StrictDiagnostic", + "autofixable": false, + "suggest": "Variable 'x' is used before being assigned.", + "rule": "Variable 'x' is used before being assigned." + } + ] +} \ No newline at end of file diff --git a/linter-4.2/test_rules/rule5.ts.relax.json b/linter-4.2/test_rules/rule5.ts.relax.json new file mode 100644 index 000000000..a6b40a086 --- /dev/null +++ b/linter-4.2/test_rules/rule5.ts.relax.json @@ -0,0 +1,11 @@ +{ + "nodes": [ + { + "line": 6, + "column": 12, + "problem": "StrictDiagnostic", + "suggest": "Variable 'x' is used before being assigned.", + "rule": "Variable 'x' is used before being assigned." + } + ] +} \ No newline at end of file diff --git a/linter-4.2/test_rules/rule5.ts.strict.json b/linter-4.2/test_rules/rule5.ts.strict.json new file mode 100644 index 000000000..a2203b7f4 --- /dev/null +++ b/linter-4.2/test_rules/rule5.ts.strict.json @@ -0,0 +1,25 @@ +{ + "nodes": [ + { + "line": 4, + "column": 8, + "problem": "VarDeclaration", + "suggest": "", + "rule": "Use \"let\" instead of \"var\" (arkts-no-var)" + }, + { + "line": 14, + "column": 5, + "problem": "VarDeclaration", + "suggest": "", + "rule": "Use \"let\" instead of \"var\" (arkts-no-var)" + }, + { + "line": 6, + "column": 12, + "problem": "StrictDiagnostic", + "suggest": "Variable 'x' is used before being assigned.", + "rule": "Variable 'x' is used before being assigned." + } + ] +} \ No newline at end of file diff --git a/linter-4.2/test_rules/rule50.ts b/linter-4.2/test_rules/rule50.ts new file mode 100644 index 000000000..0fc8c5eff --- /dev/null +++ b/linter-4.2/test_rules/rule50.ts @@ -0,0 +1,11 @@ +const Rectangle = class { + constructor(height: number, width: number) { + this.heigth = height + this.width = width + } + + heigth + width +} + +const rectangle = new Rectangle(0.0, 0.0) \ No newline at end of file diff --git a/linter-4.2/test_rules/rule50.ts.autofix.json b/linter-4.2/test_rules/rule50.ts.autofix.json new file mode 100644 index 000000000..11e00482c --- /dev/null +++ b/linter-4.2/test_rules/rule50.ts.autofix.json @@ -0,0 +1,28 @@ +{ + "nodes": [ + { + "line": 1, + "column": 19, + "problem": "ClassExpression", + "autofixable": false, + "suggest": "", + "rule": "Class literals are not supported (arkts-no-class-literals)" + }, + { + "line": 7, + "column": 5, + "problem": "AnyType", + "autofixable": false, + "suggest": "", + "rule": "Use explicit types instead of \"any\", \"unknown\" (arkts-no-any-unknown)" + }, + { + "line": 8, + "column": 5, + "problem": "AnyType", + "autofixable": false, + "suggest": "", + "rule": "Use explicit types instead of \"any\", \"unknown\" (arkts-no-any-unknown)" + } + ] +} \ No newline at end of file diff --git a/linter-4.2/test_rules/rule50.ts.relax.json b/linter-4.2/test_rules/rule50.ts.relax.json new file mode 100644 index 000000000..3c9a8d5ce --- /dev/null +++ b/linter-4.2/test_rules/rule50.ts.relax.json @@ -0,0 +1,18 @@ +{ + "nodes": [ + { + "line": 7, + "column": 5, + "problem": "AnyType", + "suggest": "", + "rule": "Use explicit types instead of \"any\", \"unknown\" (arkts-no-any-unknown)" + }, + { + "line": 8, + "column": 5, + "problem": "AnyType", + "suggest": "", + "rule": "Use explicit types instead of \"any\", \"unknown\" (arkts-no-any-unknown)" + } + ] +} \ No newline at end of file diff --git a/linter-4.2/test_rules/rule50.ts.strict.json b/linter-4.2/test_rules/rule50.ts.strict.json new file mode 100644 index 000000000..5a3910d4d --- /dev/null +++ b/linter-4.2/test_rules/rule50.ts.strict.json @@ -0,0 +1,25 @@ +{ + "nodes": [ + { + "line": 1, + "column": 19, + "problem": "ClassExpression", + "suggest": "", + "rule": "Class literals are not supported (arkts-no-class-literals)" + }, + { + "line": 7, + "column": 5, + "problem": "AnyType", + "suggest": "", + "rule": "Use explicit types instead of \"any\", \"unknown\" (arkts-no-any-unknown)" + }, + { + "line": 8, + "column": 5, + "problem": "AnyType", + "suggest": "", + "rule": "Use explicit types instead of \"any\", \"unknown\" (arkts-no-any-unknown)" + } + ] +} \ No newline at end of file diff --git a/linter-4.2/test_rules/rule51.ts b/linter-4.2/test_rules/rule51.ts new file mode 100644 index 000000000..6142f7bac --- /dev/null +++ b/linter-4.2/test_rules/rule51.ts @@ -0,0 +1,15 @@ +class C { + foo() {} + } + + class C1 implements C { + foo() {} + } + + interface D { + foo(): void + } + + class D1 implements D { + foo() {} + } \ No newline at end of file diff --git a/linter-4.2/test_rules/rule51.ts.autofix.json b/linter-4.2/test_rules/rule51.ts.autofix.json new file mode 100644 index 000000000..4e0265c93 --- /dev/null +++ b/linter-4.2/test_rules/rule51.ts.autofix.json @@ -0,0 +1,12 @@ +{ + "nodes": [ + { + "line": 5, + "column": 23, + "problem": "ImplementsClass", + "autofixable": false, + "suggest": "", + "rule": "Classes cannot be specified in \"implements\" clause (arkts-implements-only-iface)" + } + ] +} \ No newline at end of file diff --git a/linter-4.2/test_rules/rule51.ts.relax.json b/linter-4.2/test_rules/rule51.ts.relax.json new file mode 100644 index 000000000..f43015712 --- /dev/null +++ b/linter-4.2/test_rules/rule51.ts.relax.json @@ -0,0 +1,11 @@ +{ + "nodes": [ + { + "line": 5, + "column": 23, + "problem": "ImplementsClass", + "suggest": "", + "rule": "Classes cannot be specified in \"implements\" clause (arkts-implements-only-iface)" + } + ] +} \ No newline at end of file diff --git a/linter-4.2/test_rules/rule51.ts.strict.json b/linter-4.2/test_rules/rule51.ts.strict.json new file mode 100644 index 000000000..f43015712 --- /dev/null +++ b/linter-4.2/test_rules/rule51.ts.strict.json @@ -0,0 +1,11 @@ +{ + "nodes": [ + { + "line": 5, + "column": 23, + "problem": "ImplementsClass", + "suggest": "", + "rule": "Classes cannot be specified in \"implements\" clause (arkts-implements-only-iface)" + } + ] +} \ No newline at end of file diff --git a/linter-4.2/test_rules/rule52.ts b/linter-4.2/test_rules/rule52.ts new file mode 100644 index 000000000..de9a15cd1 --- /dev/null +++ b/linter-4.2/test_rules/rule52.ts @@ -0,0 +1,20 @@ +let person = {name: "Bob", isEmployee: true} + +let n = person["name"] +let e = person["isEmployee"] +let s = person["office"] + + +class Person { + constructor(name: string, isEmployee: boolean) { + this.name = name + this.isEmployee = isEmployee + } + + name: string + isEmployee: boolean +} + +let person2 = new Person("Bob", true) +let n1 = person2.name +let e1 = person2.isEmployee \ No newline at end of file diff --git a/linter-4.2/test_rules/rule52.ts.autofix.json b/linter-4.2/test_rules/rule52.ts.autofix.json new file mode 100644 index 000000000..d08778c75 --- /dev/null +++ b/linter-4.2/test_rules/rule52.ts.autofix.json @@ -0,0 +1,58 @@ +{ + "copyright": [ + "Copyright (c) 2023-2023 Huawei Device Co., Ltd.", + "Licensed under the Apache License, Version 2.0 (the 'License');", + "you may not use this file except in compliance with the License.", + "You may obtain a copy of the License at", + "", + "http://www.apache.org/licenses/LICENSE-2.0", + "", + "Unless required by applicable law or agreed to in writing, software", + "distributed under the License is distributed on an 'AS IS' BASIS,", + "WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.", + "See the License for the specific language governing permissions and", + "limitations under the License." + ], + "nodes": [ + { + "line": 1, + "column": 14, + "problem": "ObjectLiteralNoContextType", + "autofixable": false, + "suggest": "", + "rule": "Object literal must correspond to some explicitly declared class or interface (arkts-no-untyped-obj-literals)" + }, + { + "line": 3, + "column": 9, + "problem": "PropertyAccessByIndex", + "autofixable": true, + "suggest": "", + "rule": "Indexed access is not supported for fields (arkts-no-props-by-index)" + }, + { + "line": 4, + "column": 9, + "problem": "PropertyAccessByIndex", + "autofixable": true, + "suggest": "", + "rule": "Indexed access is not supported for fields (arkts-no-props-by-index)" + }, + { + "line": 5, + "column": 5, + "problem": "AnyType", + "autofixable": false, + "suggest": "", + "rule": "Use explicit types instead of \"any\", \"unknown\" (arkts-no-any-unknown)" + }, + { + "line": 5, + "column": 9, + "problem": "PropertyAccessByIndex", + "autofixable": true, + "suggest": "", + "rule": "Indexed access is not supported for fields (arkts-no-props-by-index)" + } + ] +} \ No newline at end of file diff --git a/linter-4.2/test_rules/rule52.ts.relax.json b/linter-4.2/test_rules/rule52.ts.relax.json new file mode 100644 index 000000000..093283387 --- /dev/null +++ b/linter-4.2/test_rules/rule52.ts.relax.json @@ -0,0 +1,18 @@ +{ + "nodes": [ + { + "line": 1, + "column": 14, + "problem": "ObjectLiteralNoContextType", + "suggest": "", + "rule": "Object literal must correspond to some explicitly declared class or interface (arkts-no-untyped-obj-literals)" + }, + { + "line": 5, + "column": 5, + "problem": "AnyType", + "suggest": "", + "rule": "Use explicit types instead of \"any\", \"unknown\" (arkts-no-any-unknown)" + } + ] +} \ No newline at end of file diff --git a/linter-4.2/test_rules/rule52.ts.strict.json b/linter-4.2/test_rules/rule52.ts.strict.json new file mode 100644 index 000000000..7dead8d48 --- /dev/null +++ b/linter-4.2/test_rules/rule52.ts.strict.json @@ -0,0 +1,39 @@ +{ + "nodes": [ + { + "line": 1, + "column": 14, + "problem": "ObjectLiteralNoContextType", + "suggest": "", + "rule": "Object literal must correspond to some explicitly declared class or interface (arkts-no-untyped-obj-literals)" + }, + { + "line": 3, + "column": 9, + "problem": "PropertyAccessByIndex", + "suggest": "", + "rule": "Indexed access is not supported for fields (arkts-no-props-by-index)" + }, + { + "line": 4, + "column": 9, + "problem": "PropertyAccessByIndex", + "suggest": "", + "rule": "Indexed access is not supported for fields (arkts-no-props-by-index)" + }, + { + "line": 5, + "column": 5, + "problem": "AnyType", + "suggest": "", + "rule": "Use explicit types instead of \"any\", \"unknown\" (arkts-no-any-unknown)" + }, + { + "line": 5, + "column": 9, + "problem": "PropertyAccessByIndex", + "suggest": "", + "rule": "Indexed access is not supported for fields (arkts-no-props-by-index)" + } + ] +} \ No newline at end of file diff --git a/linter-4.2/test_rules/rule53.ts b/linter-4.2/test_rules/rule53.ts new file mode 100644 index 000000000..965840212 --- /dev/null +++ b/linter-4.2/test_rules/rule53.ts @@ -0,0 +1,24 @@ +class Shape {} +class Circle extends Shape {x: number = 5} +class Square extends Shape {y: string = "a"} + +function createShape(): Shape { + return new Circle() +} + +let c1 = createShape() + +let c2 = createShape() as Circle + +// No report is provided during compilation +// nor during runtime if cast is wrong: +let c3 = createShape() as Square +console.log(c3.y) // undefined + +// Important corner case for casting primitives to the boxed counterparts: +// The left operand is not properly boxed here in in runtime +// because "as" has no runtime effect in TypeScript +let e1 = (5.0 as Number) instanceof Number // false + +// Number object is created and instanceof works as expected: +let e2 = (new Number(5.0)) instanceof Number // true \ No newline at end of file diff --git a/linter-4.2/test_rules/rule53.ts.autofix.json b/linter-4.2/test_rules/rule53.ts.autofix.json new file mode 100644 index 000000000..919e0b88f --- /dev/null +++ b/linter-4.2/test_rules/rule53.ts.autofix.json @@ -0,0 +1,27 @@ +{ + "nodes": [ + { + "line": 9, + "column": 10, + "problem": "TypeAssertion", + "autofixable": true, + "autofix": [ + { + "start": 172, + "end": 194, + "replacementText": "createShape() as Circle" + } + ], + "suggest": "", + "rule": "Only \"as T\" syntax is supported for type casts (arkts-as-casts)" + }, + { + "line": 21, + "column": 11, + "problem": "TypeAssertion", + "autofixable": false, + "suggest": "", + "rule": "Only \"as T\" syntax is supported for type casts (arkts-as-casts)" + } + ] +} \ No newline at end of file diff --git a/linter-4.2/test_rules/rule53.ts.relax.json b/linter-4.2/test_rules/rule53.ts.relax.json new file mode 100644 index 000000000..13f13363f --- /dev/null +++ b/linter-4.2/test_rules/rule53.ts.relax.json @@ -0,0 +1,3 @@ +{ + "nodes": [] +} \ No newline at end of file diff --git a/linter-4.2/test_rules/rule53.ts.strict.json b/linter-4.2/test_rules/rule53.ts.strict.json new file mode 100644 index 000000000..41e73c7be --- /dev/null +++ b/linter-4.2/test_rules/rule53.ts.strict.json @@ -0,0 +1,18 @@ +{ + "nodes": [ + { + "line": 9, + "column": 10, + "problem": "TypeAssertion", + "suggest": "", + "rule": "Only \"as T\" syntax is supported for type casts (arkts-as-casts)" + }, + { + "line": 21, + "column": 11, + "problem": "TypeAssertion", + "suggest": "", + "rule": "Only \"as T\" syntax is supported for type casts (arkts-as-casts)" + } + ] +} \ No newline at end of file diff --git a/linter-4.2/test_rules/rule55.ts b/linter-4.2/test_rules/rule55.ts new file mode 100644 index 000000000..fabc84096 --- /dev/null +++ b/linter-4.2/test_rules/rule55.ts @@ -0,0 +1,18 @@ +let a = +5 // 5 as number +let b = +"5" // 5 as number +let c = -5 // -5 as number +let d = -"5" // -5 as number +let e = ~5 // -6 as number +let f = ~"5" // -6 as number +let g = +"string" // NaN as number + +function returnTen(): string { + return "-10" +} + +function returnString(): string { + return "string" +} + +let x = +returnTen() // -10 as number +let y = +returnString() // NaN \ No newline at end of file diff --git a/linter-4.2/test_rules/rule55.ts.autofix.json b/linter-4.2/test_rules/rule55.ts.autofix.json new file mode 100644 index 000000000..c91114f5e --- /dev/null +++ b/linter-4.2/test_rules/rule55.ts.autofix.json @@ -0,0 +1,52 @@ +{ + "nodes": [ + { + "line": 2, + "column": 9, + "problem": "UnaryArithmNotNumber", + "autofixable": false, + "suggest": "", + "rule": "Unary operators \"+\", \"-\" and \"~\" work only on numbers (arkts-no-polymorphic-unops)" + }, + { + "line": 4, + "column": 9, + "problem": "UnaryArithmNotNumber", + "autofixable": false, + "suggest": "", + "rule": "Unary operators \"+\", \"-\" and \"~\" work only on numbers (arkts-no-polymorphic-unops)" + }, + { + "line": 6, + "column": 9, + "problem": "UnaryArithmNotNumber", + "autofixable": false, + "suggest": "", + "rule": "Unary operators \"+\", \"-\" and \"~\" work only on numbers (arkts-no-polymorphic-unops)" + }, + { + "line": 7, + "column": 9, + "problem": "UnaryArithmNotNumber", + "autofixable": false, + "suggest": "", + "rule": "Unary operators \"+\", \"-\" and \"~\" work only on numbers (arkts-no-polymorphic-unops)" + }, + { + "line": 17, + "column": 9, + "problem": "UnaryArithmNotNumber", + "autofixable": false, + "suggest": "", + "rule": "Unary operators \"+\", \"-\" and \"~\" work only on numbers (arkts-no-polymorphic-unops)" + }, + { + "line": 18, + "column": 9, + "problem": "UnaryArithmNotNumber", + "autofixable": false, + "suggest": "", + "rule": "Unary operators \"+\", \"-\" and \"~\" work only on numbers (arkts-no-polymorphic-unops)" + } + ] +} \ No newline at end of file diff --git a/linter-4.2/test_rules/rule55.ts.relax.json b/linter-4.2/test_rules/rule55.ts.relax.json new file mode 100644 index 000000000..cdb3b3b69 --- /dev/null +++ b/linter-4.2/test_rules/rule55.ts.relax.json @@ -0,0 +1,46 @@ +{ + "nodes": [ + { + "line": 2, + "column": 9, + "problem": "UnaryArithmNotNumber", + "suggest": "", + "rule": "Unary operators \"+\", \"-\" and \"~\" work only on numbers (arkts-no-polymorphic-unops)" + }, + { + "line": 4, + "column": 9, + "problem": "UnaryArithmNotNumber", + "suggest": "", + "rule": "Unary operators \"+\", \"-\" and \"~\" work only on numbers (arkts-no-polymorphic-unops)" + }, + { + "line": 6, + "column": 9, + "problem": "UnaryArithmNotNumber", + "suggest": "", + "rule": "Unary operators \"+\", \"-\" and \"~\" work only on numbers (arkts-no-polymorphic-unops)" + }, + { + "line": 7, + "column": 9, + "problem": "UnaryArithmNotNumber", + "suggest": "", + "rule": "Unary operators \"+\", \"-\" and \"~\" work only on numbers (arkts-no-polymorphic-unops)" + }, + { + "line": 17, + "column": 9, + "problem": "UnaryArithmNotNumber", + "suggest": "", + "rule": "Unary operators \"+\", \"-\" and \"~\" work only on numbers (arkts-no-polymorphic-unops)" + }, + { + "line": 18, + "column": 9, + "problem": "UnaryArithmNotNumber", + "suggest": "", + "rule": "Unary operators \"+\", \"-\" and \"~\" work only on numbers (arkts-no-polymorphic-unops)" + } + ] +} \ No newline at end of file diff --git a/linter-4.2/test_rules/rule55.ts.strict.json b/linter-4.2/test_rules/rule55.ts.strict.json new file mode 100644 index 000000000..cdb3b3b69 --- /dev/null +++ b/linter-4.2/test_rules/rule55.ts.strict.json @@ -0,0 +1,46 @@ +{ + "nodes": [ + { + "line": 2, + "column": 9, + "problem": "UnaryArithmNotNumber", + "suggest": "", + "rule": "Unary operators \"+\", \"-\" and \"~\" work only on numbers (arkts-no-polymorphic-unops)" + }, + { + "line": 4, + "column": 9, + "problem": "UnaryArithmNotNumber", + "suggest": "", + "rule": "Unary operators \"+\", \"-\" and \"~\" work only on numbers (arkts-no-polymorphic-unops)" + }, + { + "line": 6, + "column": 9, + "problem": "UnaryArithmNotNumber", + "suggest": "", + "rule": "Unary operators \"+\", \"-\" and \"~\" work only on numbers (arkts-no-polymorphic-unops)" + }, + { + "line": 7, + "column": 9, + "problem": "UnaryArithmNotNumber", + "suggest": "", + "rule": "Unary operators \"+\", \"-\" and \"~\" work only on numbers (arkts-no-polymorphic-unops)" + }, + { + "line": 17, + "column": 9, + "problem": "UnaryArithmNotNumber", + "suggest": "", + "rule": "Unary operators \"+\", \"-\" and \"~\" work only on numbers (arkts-no-polymorphic-unops)" + }, + { + "line": 18, + "column": 9, + "problem": "UnaryArithmNotNumber", + "suggest": "", + "rule": "Unary operators \"+\", \"-\" and \"~\" work only on numbers (arkts-no-polymorphic-unops)" + } + ] +} \ No newline at end of file diff --git a/linter-4.2/test_rules/rule59.ts b/linter-4.2/test_rules/rule59.ts new file mode 100644 index 000000000..97150733a --- /dev/null +++ b/linter-4.2/test_rules/rule59.ts @@ -0,0 +1,15 @@ +class Point { + x?: number = 0.0 + y?: number = 0.0 +} + +let p = new Point() +delete p.y + +class Point2 { + x: number | null = 0 + y: number | null = 0 +} + +let p2 = new Point() +p2.y = null \ No newline at end of file diff --git a/linter-4.2/test_rules/rule59.ts.autofix.json b/linter-4.2/test_rules/rule59.ts.autofix.json new file mode 100644 index 000000000..c7b064b9f --- /dev/null +++ b/linter-4.2/test_rules/rule59.ts.autofix.json @@ -0,0 +1,20 @@ +{ + "nodes": [ + { + "line": 7, + "column": 1, + "problem": "DeleteOperator", + "autofixable": false, + "suggest": "", + "rule": "\"delete\" operator is not supported (arkts-no-delete)" + }, + { + "line": 15, + "column": 1, + "problem": "StrictDiagnostic", + "autofixable": false, + "suggest": "Type 'null' is not assignable to type 'number | undefined'.", + "rule": "Type 'null' is not assignable to type 'number | undefined'." + } + ] +} \ No newline at end of file diff --git a/linter-4.2/test_rules/rule59.ts.relax.json b/linter-4.2/test_rules/rule59.ts.relax.json new file mode 100644 index 000000000..63b79f7f0 --- /dev/null +++ b/linter-4.2/test_rules/rule59.ts.relax.json @@ -0,0 +1,18 @@ +{ + "nodes": [ + { + "line": 7, + "column": 1, + "problem": "DeleteOperator", + "suggest": "", + "rule": "\"delete\" operator is not supported (arkts-no-delete)" + }, + { + "line": 15, + "column": 1, + "problem": "StrictDiagnostic", + "suggest": "Type 'null' is not assignable to type 'number | undefined'.", + "rule": "Type 'null' is not assignable to type 'number | undefined'." + } + ] +} \ No newline at end of file diff --git a/linter-4.2/test_rules/rule59.ts.strict.json b/linter-4.2/test_rules/rule59.ts.strict.json new file mode 100644 index 000000000..63b79f7f0 --- /dev/null +++ b/linter-4.2/test_rules/rule59.ts.strict.json @@ -0,0 +1,18 @@ +{ + "nodes": [ + { + "line": 7, + "column": 1, + "problem": "DeleteOperator", + "suggest": "", + "rule": "\"delete\" operator is not supported (arkts-no-delete)" + }, + { + "line": 15, + "column": 1, + "problem": "StrictDiagnostic", + "suggest": "Type 'null' is not assignable to type 'number | undefined'.", + "rule": "Type 'null' is not assignable to type 'number | undefined'." + } + ] +} \ No newline at end of file diff --git a/linter-4.2/test_rules/rule60.ts b/linter-4.2/test_rules/rule60.ts new file mode 100644 index 000000000..ffc67284c --- /dev/null +++ b/linter-4.2/test_rules/rule60.ts @@ -0,0 +1,13 @@ +let n1 = 42 +let s1 = "foo" +console.log(typeof n1) // "number" +console.log(typeof s1) // "string" +let n2: typeof n1 +let s2: typeof s1 + +let n3 = 42 +let s3 = "foo" +console.log(typeof n3) // "number" +console.log(typeof s3) // "string" +let n4: number +let s4: string \ No newline at end of file diff --git a/linter-4.2/test_rules/rule60.ts.autofix.json b/linter-4.2/test_rules/rule60.ts.autofix.json new file mode 100644 index 000000000..a1e116149 --- /dev/null +++ b/linter-4.2/test_rules/rule60.ts.autofix.json @@ -0,0 +1,20 @@ +{ + "nodes": [ + { + "line": 5, + "column": 9, + "problem": "TypeQuery", + "autofixable": false, + "suggest": "", + "rule": "\"typeof\" operator is allowed only in expression contexts (arkts-no-type-query)" + }, + { + "line": 6, + "column": 9, + "problem": "TypeQuery", + "autofixable": false, + "suggest": "", + "rule": "\"typeof\" operator is allowed only in expression contexts (arkts-no-type-query)" + } + ] +} \ No newline at end of file diff --git a/linter-4.2/test_rules/rule60.ts.relax.json b/linter-4.2/test_rules/rule60.ts.relax.json new file mode 100644 index 000000000..4b4c06934 --- /dev/null +++ b/linter-4.2/test_rules/rule60.ts.relax.json @@ -0,0 +1,18 @@ +{ + "nodes": [ + { + "line": 5, + "column": 9, + "problem": "TypeQuery", + "suggest": "", + "rule": "\"typeof\" operator is allowed only in expression contexts (arkts-no-type-query)" + }, + { + "line": 6, + "column": 9, + "problem": "TypeQuery", + "suggest": "", + "rule": "\"typeof\" operator is allowed only in expression contexts (arkts-no-type-query)" + } + ] +} \ No newline at end of file diff --git a/linter-4.2/test_rules/rule60.ts.strict.json b/linter-4.2/test_rules/rule60.ts.strict.json new file mode 100644 index 000000000..4b4c06934 --- /dev/null +++ b/linter-4.2/test_rules/rule60.ts.strict.json @@ -0,0 +1,18 @@ +{ + "nodes": [ + { + "line": 5, + "column": 9, + "problem": "TypeQuery", + "suggest": "", + "rule": "\"typeof\" operator is allowed only in expression contexts (arkts-no-type-query)" + }, + { + "line": 6, + "column": 9, + "problem": "TypeQuery", + "suggest": "", + "rule": "\"typeof\" operator is allowed only in expression contexts (arkts-no-type-query)" + } + ] +} \ No newline at end of file diff --git a/linter-4.2/test_rules/rule63.ts b/linter-4.2/test_rules/rule63.ts new file mode 100644 index 000000000..892bd7189 --- /dev/null +++ b/linter-4.2/test_rules/rule63.ts @@ -0,0 +1,15 @@ +enum E { E1, E2 } + +let a = 10 + 32 // 42 +let b = E.E1 + 10 // 10 +let c = 10 + "5" // "105" + +let d = "5" + E.E2 // "51" +let e = "Hello, " + "world!" // "Hello, world!" +let f = "string" + true // "stringtrue" + +let g = (new Object()) + "string" // "[object Object]string" + +let i = true + true // JS: 2, TS: compile-time error +let j = true + 2 // JS: 3, TS: compile-time error +let k = E.E1 + true // JS: 1, TS: compile-time error \ No newline at end of file diff --git a/linter-4.2/test_rules/rule63.ts.autofix.json b/linter-4.2/test_rules/rule63.ts.autofix.json new file mode 100644 index 000000000..c7b928233 --- /dev/null +++ b/linter-4.2/test_rules/rule63.ts.autofix.json @@ -0,0 +1,28 @@ +{ + "nodes": [ + { + "line": 13, + "column": 5, + "problem": "AnyType", + "autofixable": false, + "suggest": "", + "rule": "Use explicit types instead of \"any\", \"unknown\" (arkts-no-any-unknown)" + }, + { + "line": 14, + "column": 5, + "problem": "AnyType", + "autofixable": false, + "suggest": "", + "rule": "Use explicit types instead of \"any\", \"unknown\" (arkts-no-any-unknown)" + }, + { + "line": 15, + "column": 5, + "problem": "AnyType", + "autofixable": false, + "suggest": "", + "rule": "Use explicit types instead of \"any\", \"unknown\" (arkts-no-any-unknown)" + } + ] +} diff --git a/linter-4.2/test_rules/rule63.ts.relax.json b/linter-4.2/test_rules/rule63.ts.relax.json new file mode 100644 index 000000000..324172c39 --- /dev/null +++ b/linter-4.2/test_rules/rule63.ts.relax.json @@ -0,0 +1,25 @@ +{ + "nodes": [ + { + "line": 13, + "column": 5, + "problem": "AnyType", + "suggest": "", + "rule": "Use explicit types instead of \"any\", \"unknown\" (arkts-no-any-unknown)" + }, + { + "line": 14, + "column": 5, + "problem": "AnyType", + "suggest": "", + "rule": "Use explicit types instead of \"any\", \"unknown\" (arkts-no-any-unknown)" + }, + { + "line": 15, + "column": 5, + "problem": "AnyType", + "suggest": "", + "rule": "Use explicit types instead of \"any\", \"unknown\" (arkts-no-any-unknown)" + } + ] +} diff --git a/linter-4.2/test_rules/rule63.ts.strict.json b/linter-4.2/test_rules/rule63.ts.strict.json new file mode 100644 index 000000000..324172c39 --- /dev/null +++ b/linter-4.2/test_rules/rule63.ts.strict.json @@ -0,0 +1,25 @@ +{ + "nodes": [ + { + "line": 13, + "column": 5, + "problem": "AnyType", + "suggest": "", + "rule": "Use explicit types instead of \"any\", \"unknown\" (arkts-no-any-unknown)" + }, + { + "line": 14, + "column": 5, + "problem": "AnyType", + "suggest": "", + "rule": "Use explicit types instead of \"any\", \"unknown\" (arkts-no-any-unknown)" + }, + { + "line": 15, + "column": 5, + "problem": "AnyType", + "suggest": "", + "rule": "Use explicit types instead of \"any\", \"unknown\" (arkts-no-any-unknown)" + } + ] +} diff --git a/linter-4.2/test_rules/rule65.ts b/linter-4.2/test_rules/rule65.ts new file mode 100644 index 000000000..d4d849f76 --- /dev/null +++ b/linter-4.2/test_rules/rule65.ts @@ -0,0 +1,9 @@ +class X { + // ... +} + +let a = (new X()) instanceof Object // true +let b = (new X()) instanceof X // true + +let c = X instanceof Object // true, left operand is a type +let d = X instanceof X // false, left operand is a type \ No newline at end of file diff --git a/linter-4.2/test_rules/rule65.ts.autofix.json b/linter-4.2/test_rules/rule65.ts.autofix.json new file mode 100644 index 000000000..9e70ad4de --- /dev/null +++ b/linter-4.2/test_rules/rule65.ts.autofix.json @@ -0,0 +1,20 @@ +{ + "nodes": [ + { + "line": 8, + "column": 9, + "problem": "InstanceofUnsupported", + "autofixable": false, + "suggest": "", + "rule": "\"instanceof\" operator is partially supported (arkts-instanceof-ref-types)" + }, + { + "line": 9, + "column": 9, + "problem": "InstanceofUnsupported", + "autofixable": false, + "suggest": "", + "rule": "\"instanceof\" operator is partially supported (arkts-instanceof-ref-types)" + } + ] +} \ No newline at end of file diff --git a/linter-4.2/test_rules/rule65.ts.relax.json b/linter-4.2/test_rules/rule65.ts.relax.json new file mode 100644 index 000000000..050b37b68 --- /dev/null +++ b/linter-4.2/test_rules/rule65.ts.relax.json @@ -0,0 +1,18 @@ +{ + "nodes": [ + { + "line": 8, + "column": 9, + "problem": "InstanceofUnsupported", + "suggest": "", + "rule": "\"instanceof\" operator is partially supported (arkts-instanceof-ref-types)" + }, + { + "line": 9, + "column": 9, + "problem": "InstanceofUnsupported", + "suggest": "", + "rule": "\"instanceof\" operator is partially supported (arkts-instanceof-ref-types)" + } + ] +} \ No newline at end of file diff --git a/linter-4.2/test_rules/rule65.ts.strict.json b/linter-4.2/test_rules/rule65.ts.strict.json new file mode 100644 index 000000000..050b37b68 --- /dev/null +++ b/linter-4.2/test_rules/rule65.ts.strict.json @@ -0,0 +1,18 @@ +{ + "nodes": [ + { + "line": 8, + "column": 9, + "problem": "InstanceofUnsupported", + "suggest": "", + "rule": "\"instanceof\" operator is partially supported (arkts-instanceof-ref-types)" + }, + { + "line": 9, + "column": 9, + "problem": "InstanceofUnsupported", + "suggest": "", + "rule": "\"instanceof\" operator is partially supported (arkts-instanceof-ref-types)" + } + ] +} \ No newline at end of file diff --git a/linter-4.2/test_rules/rule66.ts b/linter-4.2/test_rules/rule66.ts new file mode 100644 index 000000000..b301c85fc --- /dev/null +++ b/linter-4.2/test_rules/rule66.ts @@ -0,0 +1,8 @@ +class Person { + name: string = "" +} +let p = new Person() + +let b = "name" in p + +let c = p instanceof Person \ No newline at end of file diff --git a/linter-4.2/test_rules/rule66.ts.autofix.json b/linter-4.2/test_rules/rule66.ts.autofix.json new file mode 100644 index 000000000..369960bde --- /dev/null +++ b/linter-4.2/test_rules/rule66.ts.autofix.json @@ -0,0 +1,12 @@ +{ + "nodes": [ + { + "line": 6, + "column": 16, + "problem": "InOperator", + "autofixable": false, + "suggest": "", + "rule": "\"in\" operator is not supported (arkts-no-in)" + } + ] +} \ No newline at end of file diff --git a/linter-4.2/test_rules/rule66.ts.relax.json b/linter-4.2/test_rules/rule66.ts.relax.json new file mode 100644 index 000000000..301f381a1 --- /dev/null +++ b/linter-4.2/test_rules/rule66.ts.relax.json @@ -0,0 +1,11 @@ +{ + "nodes": [ + { + "line": 6, + "column": 16, + "problem": "InOperator", + "suggest": "", + "rule": "\"in\" operator is not supported (arkts-no-in)" + } + ] +} \ No newline at end of file diff --git a/linter-4.2/test_rules/rule66.ts.strict.json b/linter-4.2/test_rules/rule66.ts.strict.json new file mode 100644 index 000000000..301f381a1 --- /dev/null +++ b/linter-4.2/test_rules/rule66.ts.strict.json @@ -0,0 +1,11 @@ +{ + "nodes": [ + { + "line": 6, + "column": 16, + "problem": "InOperator", + "suggest": "", + "rule": "\"in\" operator is not supported (arkts-no-in)" + } + ] +} \ No newline at end of file diff --git a/linter-4.2/test_rules/rule69.ts b/linter-4.2/test_rules/rule69.ts new file mode 100644 index 000000000..c61eee0cb --- /dev/null +++ b/linter-4.2/test_rules/rule69.ts @@ -0,0 +1,20 @@ +let [one, two] = [1, 2]; +[one, two] = [two, one] + +let head, tail +[head, ...tail] = [1, 2, 3, 4] + +let arr2: number[] = [1, 2] +let one2 = arr2[0] +let two2 = arr2[1] + +let tmp = one +one = two +two = tmp + +let data2: Number[] = [1, 2, 3, 4] +let head2 = data2[0] +let tail2: Number[] = [] +for (let i = 1; i < data2.length; ++i) { + tail.push(data2[i]) +} \ No newline at end of file diff --git a/linter-4.2/test_rules/rule69.ts.autofix.json b/linter-4.2/test_rules/rule69.ts.autofix.json new file mode 100644 index 000000000..0c8f1f91d --- /dev/null +++ b/linter-4.2/test_rules/rule69.ts.autofix.json @@ -0,0 +1,52 @@ +{ + "nodes": [ + { + "line": 1, + "column": 5, + "problem": "DestructuringDeclaration", + "autofixable": false, + "suggest": "", + "rule": "Destructuring variable declarations are not supported (arkts-no-destruct-decls)" + }, + { + "line": 2, + "column": 1, + "problem": "DestructuringAssignment", + "autofixable": false, + "suggest": "", + "rule": "Destructuring assignment is not supported (arkts-no-destruct-assignment)" + }, + { + "line": 4, + "column": 5, + "problem": "AnyType", + "autofixable": false, + "suggest": "", + "rule": "Use explicit types instead of \"any\", \"unknown\" (arkts-no-any-unknown)" + }, + { + "line": 4, + "column": 11, + "problem": "AnyType", + "autofixable": false, + "suggest": "", + "rule": "Use explicit types instead of \"any\", \"unknown\" (arkts-no-any-unknown)" + }, + { + "line": 5, + "column": 1, + "problem": "DestructuringAssignment", + "autofixable": false, + "suggest": "", + "rule": "Destructuring assignment is not supported (arkts-no-destruct-assignment)" + }, + { + "line": 5, + "column": 8, + "problem": "SpreadOperator", + "autofixable": false, + "suggest": "", + "rule": "It is possible to spread only arrays into the rest parameter (arkts-no-spread)" + } + ] +} \ No newline at end of file diff --git a/linter-4.2/test_rules/rule69.ts.relax.json b/linter-4.2/test_rules/rule69.ts.relax.json new file mode 100644 index 000000000..740d7e2ea --- /dev/null +++ b/linter-4.2/test_rules/rule69.ts.relax.json @@ -0,0 +1,25 @@ +{ + "nodes": [ + { + "line": 4, + "column": 5, + "problem": "AnyType", + "suggest": "", + "rule": "Use explicit types instead of \"any\", \"unknown\" (arkts-no-any-unknown)" + }, + { + "line": 4, + "column": 11, + "problem": "AnyType", + "suggest": "", + "rule": "Use explicit types instead of \"any\", \"unknown\" (arkts-no-any-unknown)" + }, + { + "line": 5, + "column": 8, + "problem": "SpreadOperator", + "suggest": "", + "rule": "It is possible to spread only arrays into the rest parameter (arkts-no-spread)" + } + ] +} \ No newline at end of file diff --git a/linter-4.2/test_rules/rule69.ts.strict.json b/linter-4.2/test_rules/rule69.ts.strict.json new file mode 100644 index 000000000..d09d39688 --- /dev/null +++ b/linter-4.2/test_rules/rule69.ts.strict.json @@ -0,0 +1,46 @@ +{ + "nodes": [ + { + "line": 1, + "column": 5, + "problem": "DestructuringDeclaration", + "suggest": "", + "rule": "Destructuring variable declarations are not supported (arkts-no-destruct-decls)" + }, + { + "line": 2, + "column": 1, + "problem": "DestructuringAssignment", + "suggest": "", + "rule": "Destructuring assignment is not supported (arkts-no-destruct-assignment)" + }, + { + "line": 4, + "column": 5, + "problem": "AnyType", + "suggest": "", + "rule": "Use explicit types instead of \"any\", \"unknown\" (arkts-no-any-unknown)" + }, + { + "line": 4, + "column": 11, + "problem": "AnyType", + "suggest": "", + "rule": "Use explicit types instead of \"any\", \"unknown\" (arkts-no-any-unknown)" + }, + { + "line": 5, + "column": 1, + "problem": "DestructuringAssignment", + "suggest": "", + "rule": "Destructuring assignment is not supported (arkts-no-destruct-assignment)" + }, + { + "line": 5, + "column": 8, + "problem": "SpreadOperator", + "suggest": "", + "rule": "It is possible to spread only arrays into the rest parameter (arkts-no-spread)" + } + ] +} \ No newline at end of file diff --git a/linter-4.2/test_rules/rule71.ts b/linter-4.2/test_rules/rule71.ts new file mode 100644 index 000000000..2f9078b63 --- /dev/null +++ b/linter-4.2/test_rules/rule71.ts @@ -0,0 +1,16 @@ +for (let i = 0, j = 0; i < 10; ++i, j += 2) { + console.log(i) + console.log(j) +} + +let x = 0 +x = (++x, x++) + +for (let i = 0, j = 0; i < 10; ++i, j += 2) { + console.log(i) + console.log(j) +} + +let x2 = 0 +++x2 +x2 = x2++ \ No newline at end of file diff --git a/linter-4.2/test_rules/rule71.ts.autofix.json b/linter-4.2/test_rules/rule71.ts.autofix.json new file mode 100644 index 000000000..0fb0c8f20 --- /dev/null +++ b/linter-4.2/test_rules/rule71.ts.autofix.json @@ -0,0 +1,12 @@ +{ + "nodes": [ + { + "line": 7, + "column": 6, + "problem": "CommaOperator", + "autofixable": false, + "suggest": "", + "rule": "The comma operator \",\" is supported only in \"for\" loops (arkts-no-comma-outside-loops)" + } + ] +} \ No newline at end of file diff --git a/linter-4.2/test_rules/rule71.ts.relax.json b/linter-4.2/test_rules/rule71.ts.relax.json new file mode 100644 index 000000000..8cc404d64 --- /dev/null +++ b/linter-4.2/test_rules/rule71.ts.relax.json @@ -0,0 +1,11 @@ +{ + "nodes": [ + { + "line": 7, + "column": 6, + "problem": "CommaOperator", + "suggest": "", + "rule": "The comma operator \",\" is supported only in \"for\" loops (arkts-no-comma-outside-loops)" + } + ] +} \ No newline at end of file diff --git a/linter-4.2/test_rules/rule71.ts.strict.json b/linter-4.2/test_rules/rule71.ts.strict.json new file mode 100644 index 000000000..8cc404d64 --- /dev/null +++ b/linter-4.2/test_rules/rule71.ts.strict.json @@ -0,0 +1,11 @@ +{ + "nodes": [ + { + "line": 7, + "column": 6, + "problem": "CommaOperator", + "suggest": "", + "rule": "The comma operator \",\" is supported only in \"for\" loops (arkts-no-comma-outside-loops)" + } + ] +} \ No newline at end of file diff --git a/linter-4.2/test_rules/rule74.ts b/linter-4.2/test_rules/rule74.ts new file mode 100644 index 000000000..63df75da4 --- /dev/null +++ b/linter-4.2/test_rules/rule74.ts @@ -0,0 +1,20 @@ +class Point { + x: number = 0.0 + y: number = 0.0 +} + +function returnZeroPoint(): Point { + return new Point() +} + +let {x, y} = returnZeroPoint() + + + +function returnZeroPoint2(): Point { + return new Point() +} + +let zp = returnZeroPoint2() +let x2 = zp.x +let y2 = zp.y \ No newline at end of file diff --git a/linter-4.2/test_rules/rule74.ts.autofix.json b/linter-4.2/test_rules/rule74.ts.autofix.json new file mode 100644 index 000000000..83a853b0a --- /dev/null +++ b/linter-4.2/test_rules/rule74.ts.autofix.json @@ -0,0 +1,12 @@ +{ + "nodes": [ + { + "line": 10, + "column": 5, + "problem": "DestructuringDeclaration", + "autofixable": false, + "suggest": "", + "rule": "Destructuring variable declarations are not supported (arkts-no-destruct-decls)" + } + ] +} \ No newline at end of file diff --git a/linter-4.2/test_rules/rule74.ts.relax.json b/linter-4.2/test_rules/rule74.ts.relax.json new file mode 100644 index 000000000..13f13363f --- /dev/null +++ b/linter-4.2/test_rules/rule74.ts.relax.json @@ -0,0 +1,3 @@ +{ + "nodes": [] +} \ No newline at end of file diff --git a/linter-4.2/test_rules/rule74.ts.strict.json b/linter-4.2/test_rules/rule74.ts.strict.json new file mode 100644 index 000000000..53af79469 --- /dev/null +++ b/linter-4.2/test_rules/rule74.ts.strict.json @@ -0,0 +1,11 @@ +{ + "nodes": [ + { + "line": 10, + "column": 5, + "problem": "DestructuringDeclaration", + "suggest": "", + "rule": "Destructuring variable declarations are not supported (arkts-no-destruct-decls)" + } + ] +} \ No newline at end of file diff --git a/linter-4.2/test_rules/rule76.ts b/linter-4.2/test_rules/rule76.ts new file mode 100644 index 000000000..d0913cbd2 --- /dev/null +++ b/linter-4.2/test_rules/rule76.ts @@ -0,0 +1,10 @@ +let [a, b, c] = [1, "hello", true] + +let a2 = 1 +let b2 = "hello" +let c2 = true + +let arr: Object[] = [1, "hello", true] +let a1 = arr[0] +let b1 = arr[1] +let c1 = arr[2] \ No newline at end of file diff --git a/linter-4.2/test_rules/rule76.ts.autofix.json b/linter-4.2/test_rules/rule76.ts.autofix.json new file mode 100644 index 000000000..84c9ce988 --- /dev/null +++ b/linter-4.2/test_rules/rule76.ts.autofix.json @@ -0,0 +1,12 @@ +{ + "nodes": [ + { + "line": 1, + "column": 5, + "problem": "DestructuringDeclaration", + "autofixable": false, + "suggest": "", + "rule": "Destructuring variable declarations are not supported (arkts-no-destruct-decls)" + } + ] +} \ No newline at end of file diff --git a/linter-4.2/test_rules/rule76.ts.relax.json b/linter-4.2/test_rules/rule76.ts.relax.json new file mode 100644 index 000000000..13f13363f --- /dev/null +++ b/linter-4.2/test_rules/rule76.ts.relax.json @@ -0,0 +1,3 @@ +{ + "nodes": [] +} \ No newline at end of file diff --git a/linter-4.2/test_rules/rule76.ts.strict.json b/linter-4.2/test_rules/rule76.ts.strict.json new file mode 100644 index 000000000..50913e605 --- /dev/null +++ b/linter-4.2/test_rules/rule76.ts.strict.json @@ -0,0 +1,11 @@ +{ + "nodes": [ + { + "line": 1, + "column": 5, + "problem": "DestructuringDeclaration", + "suggest": "", + "rule": "Destructuring variable declarations are not supported (arkts-no-destruct-decls)" + } + ] +} \ No newline at end of file diff --git a/linter-4.2/test_rules/rule79.ts b/linter-4.2/test_rules/rule79.ts new file mode 100644 index 000000000..0c35b2e63 --- /dev/null +++ b/linter-4.2/test_rules/rule79.ts @@ -0,0 +1,14 @@ +try { + // some code +} +catch (a: unknown) { + // handle error +} + + +try { + // some code +} +catch (a) { + // handle error +} \ No newline at end of file diff --git a/linter-4.2/test_rules/rule79.ts.autofix.json b/linter-4.2/test_rules/rule79.ts.autofix.json new file mode 100644 index 000000000..109518d2a --- /dev/null +++ b/linter-4.2/test_rules/rule79.ts.autofix.json @@ -0,0 +1,27 @@ +{ + "nodes": [ + { + "line": 4, + "column": 1, + "problem": "CatchWithUnsupportedType", + "autofixable": true, + "autofix": [ + { + "start": 32, + "end": 42, + "replacementText": "a" + } + ], + "suggest": "", + "rule": "Type annotation in catch clause is not supported (arkts-no-types-in-catch)" + }, + { + "line": 4, + "column": 11, + "problem": "UnknownType", + "autofixable": false, + "suggest": "", + "rule": "Use explicit types instead of \"any\", \"unknown\" (arkts-no-any-unknown)" + } + ] +} \ No newline at end of file diff --git a/linter-4.2/test_rules/rule79.ts.relax.json b/linter-4.2/test_rules/rule79.ts.relax.json new file mode 100644 index 000000000..fbfdd7e19 --- /dev/null +++ b/linter-4.2/test_rules/rule79.ts.relax.json @@ -0,0 +1,11 @@ +{ + "nodes": [ + { + "line": 4, + "column": 11, + "problem": "UnknownType", + "suggest": "", + "rule": "Use explicit types instead of \"any\", \"unknown\" (arkts-no-any-unknown)" + } + ] +} \ No newline at end of file diff --git a/linter-4.2/test_rules/rule79.ts.strict.json b/linter-4.2/test_rules/rule79.ts.strict.json new file mode 100644 index 000000000..486dbc46a --- /dev/null +++ b/linter-4.2/test_rules/rule79.ts.strict.json @@ -0,0 +1,18 @@ +{ + "nodes": [ + { + "line": 4, + "column": 1, + "problem": "CatchWithUnsupportedType", + "suggest": "", + "rule": "Type annotation in catch clause is not supported (arkts-no-types-in-catch)" + }, + { + "line": 4, + "column": 11, + "problem": "UnknownType", + "suggest": "", + "rule": "Use explicit types instead of \"any\", \"unknown\" (arkts-no-any-unknown)" + } + ] +} \ No newline at end of file diff --git a/linter-4.2/test_rules/rule8.ts b/linter-4.2/test_rules/rule8.ts new file mode 100644 index 000000000..599044e69 --- /dev/null +++ b/linter-4.2/test_rules/rule8.ts @@ -0,0 +1,13 @@ + +let value1 : any +value1 = true +value1 = 42 + +let value2 : unknown +value2 = true +value2 = 42 + +let value_b: boolean = true // OR: let value_b = true +let value_n: number = 42 // OR: let value_n = 42 +let value_o1: Object = true +let value_o2: Object = 42 \ No newline at end of file diff --git a/linter-4.2/test_rules/rule8.ts.autofix.json b/linter-4.2/test_rules/rule8.ts.autofix.json new file mode 100644 index 000000000..7bd209b8b --- /dev/null +++ b/linter-4.2/test_rules/rule8.ts.autofix.json @@ -0,0 +1,20 @@ +{ + "nodes": [ + { + "line": 2, + "column": 14, + "problem": "AnyType", + "autofixable": false, + "suggest": "", + "rule": "Use explicit types instead of \"any\", \"unknown\" (arkts-no-any-unknown)" + }, + { + "line": 6, + "column": 14, + "problem": "UnknownType", + "autofixable": false, + "suggest": "", + "rule": "Use explicit types instead of \"any\", \"unknown\" (arkts-no-any-unknown)" + } + ] +} \ No newline at end of file diff --git a/linter-4.2/test_rules/rule8.ts.relax.json b/linter-4.2/test_rules/rule8.ts.relax.json new file mode 100644 index 000000000..742ecfb7f --- /dev/null +++ b/linter-4.2/test_rules/rule8.ts.relax.json @@ -0,0 +1,18 @@ +{ + "nodes": [ + { + "line": 2, + "column": 14, + "problem": "AnyType", + "suggest": "", + "rule": "Use explicit types instead of \"any\", \"unknown\" (arkts-no-any-unknown)" + }, + { + "line": 6, + "column": 14, + "problem": "UnknownType", + "suggest": "", + "rule": "Use explicit types instead of \"any\", \"unknown\" (arkts-no-any-unknown)" + } + ] +} \ No newline at end of file diff --git a/linter-4.2/test_rules/rule8.ts.strict.json b/linter-4.2/test_rules/rule8.ts.strict.json new file mode 100644 index 000000000..742ecfb7f --- /dev/null +++ b/linter-4.2/test_rules/rule8.ts.strict.json @@ -0,0 +1,18 @@ +{ + "nodes": [ + { + "line": 2, + "column": 14, + "problem": "AnyType", + "suggest": "", + "rule": "Use explicit types instead of \"any\", \"unknown\" (arkts-no-any-unknown)" + }, + { + "line": 6, + "column": 14, + "problem": "UnknownType", + "suggest": "", + "rule": "Use explicit types instead of \"any\", \"unknown\" (arkts-no-any-unknown)" + } + ] +} \ No newline at end of file diff --git a/linter-4.2/test_rules/rule80.ts b/linter-4.2/test_rules/rule80.ts new file mode 100644 index 000000000..6385a091a --- /dev/null +++ b/linter-4.2/test_rules/rule80.ts @@ -0,0 +1,10 @@ +let a: number[] = [1.0, 2.0, 3.0] +for (let i in a) { + console.log(a[i]) +} + + +let a2: number[] = [1.0, 2.0, 3.0] +for (let i = 0; i < a2.length; ++i) { + console.log(a[i]) +} \ No newline at end of file diff --git a/linter-4.2/test_rules/rule80.ts.autofix.json b/linter-4.2/test_rules/rule80.ts.autofix.json new file mode 100644 index 000000000..54c46bffc --- /dev/null +++ b/linter-4.2/test_rules/rule80.ts.autofix.json @@ -0,0 +1,12 @@ +{ + "nodes": [ + { + "line": 2, + "column": 1, + "problem": "ForInStatement", + "autofixable": false, + "suggest": "", + "rule": "\"for .. in\" is not supported (arkts-no-for-in)" + } + ] +} \ No newline at end of file diff --git a/linter-4.2/test_rules/rule80.ts.relax.json b/linter-4.2/test_rules/rule80.ts.relax.json new file mode 100644 index 000000000..6eaffeec5 --- /dev/null +++ b/linter-4.2/test_rules/rule80.ts.relax.json @@ -0,0 +1,11 @@ +{ + "nodes": [ + { + "line": 2, + "column": 1, + "problem": "ForInStatement", + "suggest": "", + "rule": "\"for .. in\" is not supported (arkts-no-for-in)" + } + ] +} \ No newline at end of file diff --git a/linter-4.2/test_rules/rule80.ts.strict.json b/linter-4.2/test_rules/rule80.ts.strict.json new file mode 100644 index 000000000..6eaffeec5 --- /dev/null +++ b/linter-4.2/test_rules/rule80.ts.strict.json @@ -0,0 +1,11 @@ +{ + "nodes": [ + { + "line": 2, + "column": 1, + "problem": "ForInStatement", + "suggest": "", + "rule": "\"for .. in\" is not supported (arkts-no-for-in)" + } + ] +} \ No newline at end of file diff --git a/linter-4.2/test_rules/rule82.ts b/linter-4.2/test_rules/rule82.ts new file mode 100644 index 000000000..597aa69cb --- /dev/null +++ b/linter-4.2/test_rules/rule82.ts @@ -0,0 +1,9 @@ +let a: Set = new Set([1, 2, 3]) +for (let s of a) { + console.log(s) +} + +let numbers = Array.from(a.values()) +for (let n of numbers) { + console.log(n) +} \ No newline at end of file diff --git a/linter-4.2/test_rules/rule82.ts.autofix.json b/linter-4.2/test_rules/rule82.ts.autofix.json new file mode 100644 index 000000000..aa47fe476 --- /dev/null +++ b/linter-4.2/test_rules/rule82.ts.autofix.json @@ -0,0 +1,12 @@ +{ + "nodes": [ + { + "line": 2, + "column": 1, + "problem": "ForOfNonArray", + "autofixable": false, + "suggest": "", + "rule": "\"for-of\" is supported only for arrays and strings (arkts-for-of-str-arr)" + } + ] +} \ No newline at end of file diff --git a/linter-4.2/test_rules/rule82.ts.relax.json b/linter-4.2/test_rules/rule82.ts.relax.json new file mode 100644 index 000000000..13f13363f --- /dev/null +++ b/linter-4.2/test_rules/rule82.ts.relax.json @@ -0,0 +1,3 @@ +{ + "nodes": [] +} \ No newline at end of file diff --git a/linter-4.2/test_rules/rule82.ts.strict.json b/linter-4.2/test_rules/rule82.ts.strict.json new file mode 100644 index 000000000..a01df14e1 --- /dev/null +++ b/linter-4.2/test_rules/rule82.ts.strict.json @@ -0,0 +1,11 @@ +{ + "nodes": [ + { + "line": 2, + "column": 1, + "problem": "ForOfNonArray", + "suggest": "", + "rule": "\"for-of\" is supported only for arrays and strings (arkts-for-of-str-arr)" + } + ] +} \ No newline at end of file diff --git a/linter-4.2/test_rules/rule83.ts b/linter-4.2/test_rules/rule83.ts new file mode 100644 index 000000000..6ac377bfc --- /dev/null +++ b/linter-4.2/test_rules/rule83.ts @@ -0,0 +1,13 @@ +type OptionsFlags = { + [Property in keyof Type]: boolean +} + +class C { + n: number = 0 + s: string = "" +} + +class CFlags { + n: boolean = false + s: boolean = false +} diff --git a/linter-4.2/test_rules/rule83.ts.autofix.json b/linter-4.2/test_rules/rule83.ts.autofix.json new file mode 100644 index 000000000..5d0cd5d88 --- /dev/null +++ b/linter-4.2/test_rules/rule83.ts.autofix.json @@ -0,0 +1,20 @@ +{ + "nodes": [ + { + "line": 1, + "column": 27, + "problem": "MappedType", + "autofixable": false, + "suggest": "", + "rule": "Mapped type expression is not supported (arkts-no-mapped-types)" + }, + { + "line": 2, + "column": 18, + "problem": "KeyOfOperator", + "autofixable": false, + "suggest": "", + "rule": "\"keyof\" operator is not supported (arkts-no-keyof)" + } + ] +} \ No newline at end of file diff --git a/linter-4.2/test_rules/rule83.ts.relax.json b/linter-4.2/test_rules/rule83.ts.relax.json new file mode 100644 index 000000000..50f8420e9 --- /dev/null +++ b/linter-4.2/test_rules/rule83.ts.relax.json @@ -0,0 +1,18 @@ +{ + "nodes": [ + { + "line": 1, + "column": 27, + "problem": "MappedType", + "suggest": "", + "rule": "Mapped type expression is not supported (arkts-no-mapped-types)" + }, + { + "line": 2, + "column": 18, + "problem": "KeyOfOperator", + "suggest": "", + "rule": "\"keyof\" operator is not supported (arkts-no-keyof)" + } + ] +} \ No newline at end of file diff --git a/linter-4.2/test_rules/rule83.ts.strict.json b/linter-4.2/test_rules/rule83.ts.strict.json new file mode 100644 index 000000000..50f8420e9 --- /dev/null +++ b/linter-4.2/test_rules/rule83.ts.strict.json @@ -0,0 +1,18 @@ +{ + "nodes": [ + { + "line": 1, + "column": 27, + "problem": "MappedType", + "suggest": "", + "rule": "Mapped type expression is not supported (arkts-no-mapped-types)" + }, + { + "line": 2, + "column": 18, + "problem": "KeyOfOperator", + "suggest": "", + "rule": "\"keyof\" operator is not supported (arkts-no-keyof)" + } + ] +} \ No newline at end of file diff --git a/linter-4.2/test_rules/rule84.ts b/linter-4.2/test_rules/rule84.ts new file mode 100644 index 000000000..343706f1b --- /dev/null +++ b/linter-4.2/test_rules/rule84.ts @@ -0,0 +1,7 @@ +with (Math) { // Compile-time error, but JavaScript code still emitted + let r: number = 42 + console.log("Area: ", PI * r * r) +} + +let r: number = 42 +console.log("Area: ", Math.PI * r * r) \ No newline at end of file diff --git a/linter-4.2/test_rules/rule84.ts.autofix.json b/linter-4.2/test_rules/rule84.ts.autofix.json new file mode 100644 index 000000000..cb2a15285 --- /dev/null +++ b/linter-4.2/test_rules/rule84.ts.autofix.json @@ -0,0 +1,12 @@ +{ + "nodes": [ + { + "line": 1, + "column": 1, + "problem": "WithStatement", + "autofixable": false, + "suggest": "", + "rule": "\"with\" statement is not supported (arkts-no-with)" + } + ] +} \ No newline at end of file diff --git a/linter-4.2/test_rules/rule84.ts.relax.json b/linter-4.2/test_rules/rule84.ts.relax.json new file mode 100644 index 000000000..235ef43d7 --- /dev/null +++ b/linter-4.2/test_rules/rule84.ts.relax.json @@ -0,0 +1,11 @@ +{ + "nodes": [ + { + "line": 1, + "column": 1, + "problem": "WithStatement", + "suggest": "", + "rule": "\"with\" statement is not supported (arkts-no-with)" + } + ] +} \ No newline at end of file diff --git a/linter-4.2/test_rules/rule84.ts.strict.json b/linter-4.2/test_rules/rule84.ts.strict.json new file mode 100644 index 000000000..235ef43d7 --- /dev/null +++ b/linter-4.2/test_rules/rule84.ts.strict.json @@ -0,0 +1,11 @@ +{ + "nodes": [ + { + "line": 1, + "column": 1, + "problem": "WithStatement", + "suggest": "", + "rule": "\"with\" statement is not supported (arkts-no-with)" + } + ] +} \ No newline at end of file diff --git a/linter-4.2/test_rules/rule87.ts b/linter-4.2/test_rules/rule87.ts new file mode 100644 index 000000000..59e4f8229 --- /dev/null +++ b/linter-4.2/test_rules/rule87.ts @@ -0,0 +1,3 @@ +throw 4 +throw "" +throw new Error() \ No newline at end of file diff --git a/linter-4.2/test_rules/rule87.ts.autofix.json b/linter-4.2/test_rules/rule87.ts.autofix.json new file mode 100644 index 000000000..c361e7f53 --- /dev/null +++ b/linter-4.2/test_rules/rule87.ts.autofix.json @@ -0,0 +1,34 @@ +{ + "nodes": [ + { + "line": 1, + "column": 1, + "problem": "ThrowStatement", + "autofixable": true, + "autofix": [ + { + "start": 6, + "end": 7, + "replacementText": "new Error('', 4)" + } + ], + "suggest": "", + "rule": "\"throw\" statements cannot accept values of arbitrary types (arkts-limited-throw)" + }, + { + "line": 2, + "column": 1, + "problem": "ThrowStatement", + "autofixable": true, + "autofix": [ + { + "start": 14, + "end": 16, + "replacementText": "new Error(\"\")" + } + ], + "suggest": "", + "rule": "\"throw\" statements cannot accept values of arbitrary types (arkts-limited-throw)" + } + ] +} \ No newline at end of file diff --git a/linter-4.2/test_rules/rule87.ts.relax.json b/linter-4.2/test_rules/rule87.ts.relax.json new file mode 100644 index 000000000..13f13363f --- /dev/null +++ b/linter-4.2/test_rules/rule87.ts.relax.json @@ -0,0 +1,3 @@ +{ + "nodes": [] +} \ No newline at end of file diff --git a/linter-4.2/test_rules/rule87.ts.strict.json b/linter-4.2/test_rules/rule87.ts.strict.json new file mode 100644 index 000000000..c8b63f39e --- /dev/null +++ b/linter-4.2/test_rules/rule87.ts.strict.json @@ -0,0 +1,18 @@ +{ + "nodes": [ + { + "line": 1, + "column": 1, + "problem": "ThrowStatement", + "suggest": "", + "rule": "\"throw\" statements cannot accept values of arbitrary types (arkts-limited-throw)" + }, + { + "line": 2, + "column": 1, + "problem": "ThrowStatement", + "suggest": "", + "rule": "\"throw\" statements cannot accept values of arbitrary types (arkts-limited-throw)" + } + ] +} \ No newline at end of file diff --git a/linter-4.2/test_rules/rule90.ts b/linter-4.2/test_rules/rule90.ts new file mode 100644 index 000000000..b73bc8f2c --- /dev/null +++ b/linter-4.2/test_rules/rule90.ts @@ -0,0 +1,37 @@ + // Compile-time error with noImplicitAny + function f(x: number) { + if (x <= 0) { + return x + } + return g(x) + } + + // Compile-time error with noImplicitAny + function g(x: number) { + return f(x - 1) + } + + function doOperation(x: number, y: number) { + return x + y + } + + console.log(f(10)) + console.log(doOperation(2, 3)) + + function f1(x: number) : number { + if (x <= 0) { + return x + } + return g1(x) + } + + function g1(x: number) { + return f1(x - 1) + } + + function doOperation1(x: number, y: number) { + return x + y + } + + console.log(f1(10)) + console.log(doOperation1(2, 3)) \ No newline at end of file diff --git a/linter-4.2/test_rules/rule90.ts.autofix.json b/linter-4.2/test_rules/rule90.ts.autofix.json new file mode 100644 index 000000000..a4cb311ed --- /dev/null +++ b/linter-4.2/test_rules/rule90.ts.autofix.json @@ -0,0 +1,20 @@ +{ + "nodes": [ + { + "line": 2, + "column": 5, + "problem": "LimitedReturnTypeInference", + "autofixable": false, + "suggest": "", + "rule": "Function return type inference is limited (arkts-no-implicit-return-types)" + }, + { + "line": 10, + "column": 5, + "problem": "LimitedReturnTypeInference", + "autofixable": false, + "suggest": "", + "rule": "Function return type inference is limited (arkts-no-implicit-return-types)" + } + ] +} \ No newline at end of file diff --git a/linter-4.2/test_rules/rule90.ts.relax.json b/linter-4.2/test_rules/rule90.ts.relax.json new file mode 100644 index 000000000..13f13363f --- /dev/null +++ b/linter-4.2/test_rules/rule90.ts.relax.json @@ -0,0 +1,3 @@ +{ + "nodes": [] +} \ No newline at end of file diff --git a/linter-4.2/test_rules/rule90.ts.strict.json b/linter-4.2/test_rules/rule90.ts.strict.json new file mode 100644 index 000000000..5210923de --- /dev/null +++ b/linter-4.2/test_rules/rule90.ts.strict.json @@ -0,0 +1,18 @@ +{ + "nodes": [ + { + "line": 2, + "column": 5, + "problem": "LimitedReturnTypeInference", + "suggest": "", + "rule": "Function return type inference is limited (arkts-no-implicit-return-types)" + }, + { + "line": 10, + "column": 5, + "problem": "LimitedReturnTypeInference", + "suggest": "", + "rule": "Function return type inference is limited (arkts-no-implicit-return-types)" + } + ] +} \ No newline at end of file diff --git a/linter-4.2/test_rules/rule91.ts b/linter-4.2/test_rules/rule91.ts new file mode 100644 index 000000000..6fb94a787 --- /dev/null +++ b/linter-4.2/test_rules/rule91.ts @@ -0,0 +1,22 @@ +function drawText({ text = "", location: [x, y] = [0, 0], bold = false }) { + console.log(text) + console.log(x) + console.log(y) + console.log(bold) +} + +drawText({ text: "Hello, world!", location: [100, 50], bold: true }) + + +function drawText1(text: String, location: number[], bold: boolean) { + let x = location[0] + let y = location[1] + console.log(text) + console.log(x) + console.log(y) + console.log(bold) +} + +function main() { + drawText1("Hello, world!", [100, 50], true) +} \ No newline at end of file diff --git a/linter-4.2/test_rules/rule91.ts.autofix.json b/linter-4.2/test_rules/rule91.ts.autofix.json new file mode 100644 index 000000000..5d1531ea7 --- /dev/null +++ b/linter-4.2/test_rules/rule91.ts.autofix.json @@ -0,0 +1,20 @@ +{ + "nodes": [ + { + "line": 1, + "column": 19, + "problem": "DestructuringParameter", + "autofixable": false, + "suggest": "", + "rule": "Destructuring parameter declarations are not supported (arkts-no-destruct-params)" + }, + { + "line": 8, + "column": 10, + "problem": "ObjectLiteralNoContextType", + "autofixable": false, + "suggest": "", + "rule": "Object literal must correspond to some explicitly declared class or interface (arkts-no-untyped-obj-literals)" + } + ] +} \ No newline at end of file diff --git a/linter-4.2/test_rules/rule91.ts.relax.json b/linter-4.2/test_rules/rule91.ts.relax.json new file mode 100644 index 000000000..f0f7ff989 --- /dev/null +++ b/linter-4.2/test_rules/rule91.ts.relax.json @@ -0,0 +1,18 @@ +{ + "nodes": [ + { + "line": 1, + "column": 19, + "problem": "DestructuringParameter", + "suggest": "", + "rule": "Destructuring parameter declarations are not supported (arkts-no-destruct-params)" + }, + { + "line": 8, + "column": 10, + "problem": "ObjectLiteralNoContextType", + "suggest": "", + "rule": "Object literal must correspond to some explicitly declared class or interface (arkts-no-untyped-obj-literals)" + } + ] +} \ No newline at end of file diff --git a/linter-4.2/test_rules/rule91.ts.strict.json b/linter-4.2/test_rules/rule91.ts.strict.json new file mode 100644 index 000000000..f0f7ff989 --- /dev/null +++ b/linter-4.2/test_rules/rule91.ts.strict.json @@ -0,0 +1,18 @@ +{ + "nodes": [ + { + "line": 1, + "column": 19, + "problem": "DestructuringParameter", + "suggest": "", + "rule": "Destructuring parameter declarations are not supported (arkts-no-destruct-params)" + }, + { + "line": 8, + "column": 10, + "problem": "ObjectLiteralNoContextType", + "suggest": "", + "rule": "Object literal must correspond to some explicitly declared class or interface (arkts-no-untyped-obj-literals)" + } + ] +} \ No newline at end of file diff --git a/linter-4.2/test_rules/rule92.ts b/linter-4.2/test_rules/rule92.ts new file mode 100644 index 000000000..24d92acfc --- /dev/null +++ b/linter-4.2/test_rules/rule92.ts @@ -0,0 +1,21 @@ +function addNum(a: number, b: number): void { + function logToConsole(message: String): void { + console.log(message) + } + + let result = a + b + + logToConsole("result is " + result) +} + + +function addNum2(a: number, b: number): void { + // Use lambda instead of a nested function: + let logToConsole: (message: string) => void = (message: string): void => { + console.log(message) + } + + let result = a + b + + logToConsole("result is " + result) +} \ No newline at end of file diff --git a/linter-4.2/test_rules/rule92.ts.autofix.json b/linter-4.2/test_rules/rule92.ts.autofix.json new file mode 100644 index 000000000..e19730492 --- /dev/null +++ b/linter-4.2/test_rules/rule92.ts.autofix.json @@ -0,0 +1,12 @@ +{ + "nodes": [ + { + "line": 2, + "column": 5, + "problem": "LocalFunction", + "autofixable": false, + "suggest": "", + "rule": "Nested functions are not supported (arkts-no-nested-funcs)" + } + ] +} \ No newline at end of file diff --git a/linter-4.2/test_rules/rule92.ts.relax.json b/linter-4.2/test_rules/rule92.ts.relax.json new file mode 100644 index 000000000..13f13363f --- /dev/null +++ b/linter-4.2/test_rules/rule92.ts.relax.json @@ -0,0 +1,3 @@ +{ + "nodes": [] +} \ No newline at end of file diff --git a/linter-4.2/test_rules/rule92.ts.strict.json b/linter-4.2/test_rules/rule92.ts.strict.json new file mode 100644 index 000000000..f63a41316 --- /dev/null +++ b/linter-4.2/test_rules/rule92.ts.strict.json @@ -0,0 +1,11 @@ +{ + "nodes": [ + { + "line": 2, + "column": 5, + "problem": "LocalFunction", + "suggest": "", + "rule": "Nested functions are not supported (arkts-no-nested-funcs)" + } + ] +} \ No newline at end of file diff --git a/linter-4.2/test_rules/rule93.ts b/linter-4.2/test_rules/rule93.ts new file mode 100644 index 000000000..76703f201 --- /dev/null +++ b/linter-4.2/test_rules/rule93.ts @@ -0,0 +1,27 @@ +function foo(i: number) { + this.count = i // Compile-time error only with noImplicitThis +} + +class A { + count: number = 1 + m = foo +} + +let a = new A() +console.log(a.count) // prints "1" +a.m(2) +console.log(a.count) // prints "2" + +class A1 { + count: number = 1 + m(i: number): void { + this.count = i + } +} + +function main(): void { + let a = new A1() + console.log(a.count) // prints "1" + a.m(2) + console.log(a.count) // prints "2" +} diff --git a/linter-4.2/test_rules/rule93.ts.autofix.json b/linter-4.2/test_rules/rule93.ts.autofix.json new file mode 100644 index 000000000..872acd394 --- /dev/null +++ b/linter-4.2/test_rules/rule93.ts.autofix.json @@ -0,0 +1,12 @@ +{ + "nodes": [ + { + "line": 1, + "column": 1, + "problem": "FunctionContainsThis", + "autofixable": false, + "suggest": "", + "rule": "Using \"this\" inside stand-alone functions is not supported (arkts-no-standalone-this)" + } + ] +} \ No newline at end of file diff --git a/linter-4.2/test_rules/rule93.ts.relax.json b/linter-4.2/test_rules/rule93.ts.relax.json new file mode 100644 index 000000000..a16283a18 --- /dev/null +++ b/linter-4.2/test_rules/rule93.ts.relax.json @@ -0,0 +1,11 @@ +{ + "nodes": [ + { + "line": 1, + "column": 1, + "problem": "FunctionContainsThis", + "suggest": "", + "rule": "Using \"this\" inside stand-alone functions is not supported (arkts-no-standalone-this)" + } + ] +} \ No newline at end of file diff --git a/linter-4.2/test_rules/rule93.ts.strict.json b/linter-4.2/test_rules/rule93.ts.strict.json new file mode 100644 index 000000000..a16283a18 --- /dev/null +++ b/linter-4.2/test_rules/rule93.ts.strict.json @@ -0,0 +1,11 @@ +{ + "nodes": [ + { + "line": 1, + "column": 1, + "problem": "FunctionContainsThis", + "suggest": "", + "rule": "Using \"this\" inside stand-alone functions is not supported (arkts-no-standalone-this)" + } + ] +} \ No newline at end of file diff --git a/linter-4.2/test_rules/rule94.ts b/linter-4.2/test_rules/rule94.ts new file mode 100644 index 000000000..970288c10 --- /dev/null +++ b/linter-4.2/test_rules/rule94.ts @@ -0,0 +1,22 @@ +function* counter(start: number, end: number) { + for (let i = start; i <= end; i++) { + yield i + } +} + +for (let num of counter(1, 5)) { + console.log(num) +} + + +async function complexNumberProcessing(n : number) : Promise { + return n +} + +async function foo() { + for (let i = 1; i <= 5; i++) { + console.log(await complexNumberProcessing(i)) + } +} + +foo() diff --git a/linter-4.2/test_rules/rule94.ts.autofix.json b/linter-4.2/test_rules/rule94.ts.autofix.json new file mode 100644 index 000000000..76137f30e --- /dev/null +++ b/linter-4.2/test_rules/rule94.ts.autofix.json @@ -0,0 +1,28 @@ +{ + "nodes": [ + { + "line": 1, + "column": 1, + "problem": "GeneratorFunction", + "autofixable": false, + "suggest": "", + "rule": "Generator functions are not supported (arkts-no-generators)" + }, + { + "line": 3, + "column": 9, + "problem": "YieldExpression", + "autofixable": false, + "suggest": "", + "rule": "Generator functions are not supported (arkts-no-generators)" + }, + { + "line": 7, + "column": 1, + "problem": "ForOfNonArray", + "autofixable": false, + "suggest": "", + "rule": "\"for-of\" is supported only for arrays and strings (arkts-for-of-str-arr)" + } + ] +} \ No newline at end of file diff --git a/linter-4.2/test_rules/rule94.ts.relax.json b/linter-4.2/test_rules/rule94.ts.relax.json new file mode 100644 index 000000000..71dfc04e8 --- /dev/null +++ b/linter-4.2/test_rules/rule94.ts.relax.json @@ -0,0 +1,18 @@ +{ + "nodes": [ + { + "line": 1, + "column": 1, + "problem": "GeneratorFunction", + "suggest": "", + "rule": "Generator functions are not supported (arkts-no-generators)" + }, + { + "line": 3, + "column": 9, + "problem": "YieldExpression", + "suggest": "", + "rule": "Generator functions are not supported (arkts-no-generators)" + } + ] +} \ No newline at end of file diff --git a/linter-4.2/test_rules/rule94.ts.strict.json b/linter-4.2/test_rules/rule94.ts.strict.json new file mode 100644 index 000000000..731c59823 --- /dev/null +++ b/linter-4.2/test_rules/rule94.ts.strict.json @@ -0,0 +1,25 @@ +{ + "nodes": [ + { + "line": 1, + "column": 1, + "problem": "GeneratorFunction", + "suggest": "", + "rule": "Generator functions are not supported (arkts-no-generators)" + }, + { + "line": 3, + "column": 9, + "problem": "YieldExpression", + "suggest": "", + "rule": "Generator functions are not supported (arkts-no-generators)" + }, + { + "line": 7, + "column": 1, + "problem": "ForOfNonArray", + "suggest": "", + "rule": "\"for-of\" is supported only for arrays and strings (arkts-for-of-str-arr)" + } + ] +} \ No newline at end of file diff --git a/linter-4.2/test_rules/rule96.ts b/linter-4.2/test_rules/rule96.ts new file mode 100644 index 000000000..b71008939 --- /dev/null +++ b/linter-4.2/test_rules/rule96.ts @@ -0,0 +1,48 @@ +class Foo { + foo: number = 0 + common: string = "" +} + +class Bar { + bar: number = 0 + common: string = "" +} + +function isFoo(arg: any): arg is Foo { + return arg.foo !== undefined +} + +function doStuff(arg: Foo | Bar) { + if (isFoo(arg)) { + console.log(arg.foo) // OK + console.log(arg.bar) // Compile-time error + } else { + console.log(arg.foo) // Compile-time error + console.log(arg.bar) // OK + } +} + +doStuff({ foo: 123, common: '123' }) +doStuff({ bar: 123, common: '123' }) + + +function isFoo2(arg: Object): boolean { + return arg instanceof Foo +} + +function doStuff2(arg: Object): void { + if (isFoo2(arg)) { + let fooArg = arg as Foo + console.log(fooArg.foo) // OK + console.log(arg.bar) // Compile-time error + } else { + let barArg = arg as Bar + console.log(arg.foo) // Compile-time error + console.log(barArg.bar) // OK + } +} + +function main(): void { + doStuff2(new Foo()) + doStuff2(new Bar()) +} \ No newline at end of file diff --git a/linter-4.2/test_rules/rule96.ts.autofix.json b/linter-4.2/test_rules/rule96.ts.autofix.json new file mode 100644 index 000000000..ab7af149d --- /dev/null +++ b/linter-4.2/test_rules/rule96.ts.autofix.json @@ -0,0 +1,20 @@ +{ + "nodes": [ + { + "line": 11, + "column": 21, + "problem": "AnyType", + "autofixable": false, + "suggest": "", + "rule": "Use explicit types instead of \"any\", \"unknown\" (arkts-no-any-unknown)" + }, + { + "line": 11, + "column": 27, + "problem": "IsOperator", + "autofixable": false, + "suggest": "", + "rule": "Type guarding is supported with \"instanceof\" and \"as\" (arkts-no-is)" + } + ] +} \ No newline at end of file diff --git a/linter-4.2/test_rules/rule96.ts.relax.json b/linter-4.2/test_rules/rule96.ts.relax.json new file mode 100644 index 000000000..1840c4391 --- /dev/null +++ b/linter-4.2/test_rules/rule96.ts.relax.json @@ -0,0 +1,18 @@ +{ + "nodes": [ + { + "line": 11, + "column": 21, + "problem": "AnyType", + "suggest": "", + "rule": "Use explicit types instead of \"any\", \"unknown\" (arkts-no-any-unknown)" + }, + { + "line": 11, + "column": 27, + "problem": "IsOperator", + "suggest": "", + "rule": "Type guarding is supported with \"instanceof\" and \"as\" (arkts-no-is)" + } + ] +} \ No newline at end of file diff --git a/linter-4.2/test_rules/rule96.ts.strict.json b/linter-4.2/test_rules/rule96.ts.strict.json new file mode 100644 index 000000000..1840c4391 --- /dev/null +++ b/linter-4.2/test_rules/rule96.ts.strict.json @@ -0,0 +1,18 @@ +{ + "nodes": [ + { + "line": 11, + "column": 21, + "problem": "AnyType", + "suggest": "", + "rule": "Use explicit types instead of \"any\", \"unknown\" (arkts-no-any-unknown)" + }, + { + "line": 11, + "column": 27, + "problem": "IsOperator", + "suggest": "", + "rule": "Type guarding is supported with \"instanceof\" and \"as\" (arkts-no-is)" + } + ] +} \ No newline at end of file diff --git a/linter-4.2/test_rules/rule97.ts b/linter-4.2/test_rules/rule97.ts new file mode 100644 index 000000000..d09329799 --- /dev/null +++ b/linter-4.2/test_rules/rule97.ts @@ -0,0 +1,30 @@ +class Point { + x: number = 1 + y: number = 2 +} + +type PointKeys = keyof Point // The type of PointKeys is "x" | "y" + +function getPropertyValue(obj: Point, key: PointKeys) { + return obj[key] +} + +let obj = new Point() +console.log(getPropertyValue(obj, "x")) +console.log(getPropertyValue(obj, "y")) + +function getPropertyValue1(obj: Point, key: string): number { + if (key == "x") { + return obj.x + } + if (key == "y") { + return obj.y + } + throw new Error() +} + +function main(): void { + let obj = new Point() + console.log(getPropertyValue1(obj, "x")) + console.log(getPropertyValue1(obj, "y")) +} \ No newline at end of file diff --git a/linter-4.2/test_rules/rule97.ts.autofix.json b/linter-4.2/test_rules/rule97.ts.autofix.json new file mode 100644 index 000000000..eac151554 --- /dev/null +++ b/linter-4.2/test_rules/rule97.ts.autofix.json @@ -0,0 +1,20 @@ +{ + "nodes": [ + { + "line": 6, + "column": 18, + "problem": "KeyOfOperator", + "autofixable": false, + "suggest": "", + "rule": "\"keyof\" operator is not supported (arkts-no-keyof)" + }, + { + "line": 9, + "column": 12, + "problem": "PropertyAccessByIndex", + "autofixable": false, + "suggest": "", + "rule": "Indexed access is not supported for fields (arkts-no-props-by-index)" + } + ] +} \ No newline at end of file diff --git a/linter-4.2/test_rules/rule97.ts.relax.json b/linter-4.2/test_rules/rule97.ts.relax.json new file mode 100644 index 000000000..0a345106b --- /dev/null +++ b/linter-4.2/test_rules/rule97.ts.relax.json @@ -0,0 +1,11 @@ +{ + "nodes": [ + { + "line": 6, + "column": 18, + "problem": "KeyOfOperator", + "suggest": "", + "rule": "\"keyof\" operator is not supported (arkts-no-keyof)" + } + ] +} \ No newline at end of file diff --git a/linter-4.2/test_rules/rule97.ts.strict.json b/linter-4.2/test_rules/rule97.ts.strict.json new file mode 100644 index 000000000..6756e9a0b --- /dev/null +++ b/linter-4.2/test_rules/rule97.ts.strict.json @@ -0,0 +1,18 @@ +{ + "nodes": [ + { + "line": 6, + "column": 18, + "problem": "KeyOfOperator", + "suggest": "", + "rule": "\"keyof\" operator is not supported (arkts-no-keyof)" + }, + { + "line": 9, + "column": 12, + "problem": "PropertyAccessByIndex", + "suggest": "", + "rule": "Indexed access is not supported for fields (arkts-no-props-by-index)" + } + ] +} \ No newline at end of file diff --git a/linter-4.2/test_rules/rule99.ts b/linter-4.2/test_rules/rule99.ts new file mode 100644 index 000000000..61f72c85a --- /dev/null +++ b/linter-4.2/test_rules/rule99.ts @@ -0,0 +1,48 @@ +function foo(x : number, y : number, z : number) { + console.log(x, y, z) +} + +let args : [number, number, number] = [0, 1, 2] +foo(...args) + +let list1 = [1, 2] +let list2 = [...list1, 3, 4] + +let point2d = {x: 1, y: 2} +let point3d = {...point2d, z: 3} + + + + +function sum_numbers(...numbers: number[]): number { + let res = 0 + for (let n of numbers) + res += n + return res +} +console.log(sum_numbers(1, 2, 3)) + +function log_numbers(x : number, y : number, z : number) { + console.log(x, y, z) +} +let numbers: number[] = [1, 2, 3] +log_numbers(numbers[0], numbers[1], numbers[2]) + +let list3 : number[] = [1, 2] +let list4 : number[] = [list1[0], list1[1], 3, 4] + +class Point2D { + x: number = 0; y: number = 0 +} + +class Point3D { + x: number = 0; y: number = 0; z: number = 0 + constructor(p2d: Point2D, z: number) { + this.x = p2d.x + this.y = p2d.y + this.z = z + } +} + +let p3d = new Point3D({x: 1, y: 2} as Point2D, 3) +console.log(p3d.x, p3d.y, p3d.z) \ No newline at end of file diff --git a/linter-4.2/test_rules/rule99.ts.autofix.json b/linter-4.2/test_rules/rule99.ts.autofix.json new file mode 100644 index 000000000..b2639eb97 --- /dev/null +++ b/linter-4.2/test_rules/rule99.ts.autofix.json @@ -0,0 +1,52 @@ +{ + "nodes": [ + { + "line": 5, + "column": 12, + "problem": "TupleType", + "autofixable": false, + "suggest": "", + "rule": "Use \"Object[]\" instead of tuples (arkts-no-tuples)" + }, + { + "line": 6, + "column": 5, + "problem": "SpreadOperator", + "autofixable": false, + "suggest": "", + "rule": "It is possible to spread only arrays into the rest parameter (arkts-no-spread)" + }, + { + "line": 9, + "column": 14, + "problem": "SpreadOperator", + "autofixable": false, + "suggest": "", + "rule": "It is possible to spread only arrays into the rest parameter (arkts-no-spread)" + }, + { + "line": 11, + "column": 15, + "problem": "ObjectLiteralNoContextType", + "autofixable": false, + "suggest": "", + "rule": "Object literal must correspond to some explicitly declared class or interface (arkts-no-untyped-obj-literals)" + }, + { + "line": 12, + "column": 15, + "problem": "ObjectLiteralNoContextType", + "autofixable": false, + "suggest": "", + "rule": "Object literal must correspond to some explicitly declared class or interface (arkts-no-untyped-obj-literals)" + }, + { + "line": 12, + "column": 16, + "problem": "SpreadOperator", + "autofixable": false, + "suggest": "", + "rule": "It is possible to spread only arrays into the rest parameter (arkts-no-spread)" + } + ] +} \ No newline at end of file diff --git a/linter-4.2/test_rules/rule99.ts.relax.json b/linter-4.2/test_rules/rule99.ts.relax.json new file mode 100644 index 000000000..df5204fcf --- /dev/null +++ b/linter-4.2/test_rules/rule99.ts.relax.json @@ -0,0 +1,46 @@ +{ + "nodes": [ + { + "line": 5, + "column": 12, + "problem": "TupleType", + "suggest": "", + "rule": "Use \"Object[]\" instead of tuples (arkts-no-tuples)" + }, + { + "line": 6, + "column": 5, + "problem": "SpreadOperator", + "suggest": "", + "rule": "It is possible to spread only arrays into the rest parameter (arkts-no-spread)" + }, + { + "line": 9, + "column": 14, + "problem": "SpreadOperator", + "suggest": "", + "rule": "It is possible to spread only arrays into the rest parameter (arkts-no-spread)" + }, + { + "line": 11, + "column": 15, + "problem": "ObjectLiteralNoContextType", + "suggest": "", + "rule": "Object literal must correspond to some explicitly declared class or interface (arkts-no-untyped-obj-literals)" + }, + { + "line": 12, + "column": 15, + "problem": "ObjectLiteralNoContextType", + "suggest": "", + "rule": "Object literal must correspond to some explicitly declared class or interface (arkts-no-untyped-obj-literals)" + }, + { + "line": 12, + "column": 16, + "problem": "SpreadOperator", + "suggest": "", + "rule": "It is possible to spread only arrays into the rest parameter (arkts-no-spread)" + } + ] +} \ No newline at end of file diff --git a/linter-4.2/test_rules/rule99.ts.strict.json b/linter-4.2/test_rules/rule99.ts.strict.json new file mode 100644 index 000000000..df5204fcf --- /dev/null +++ b/linter-4.2/test_rules/rule99.ts.strict.json @@ -0,0 +1,46 @@ +{ + "nodes": [ + { + "line": 5, + "column": 12, + "problem": "TupleType", + "suggest": "", + "rule": "Use \"Object[]\" instead of tuples (arkts-no-tuples)" + }, + { + "line": 6, + "column": 5, + "problem": "SpreadOperator", + "suggest": "", + "rule": "It is possible to spread only arrays into the rest parameter (arkts-no-spread)" + }, + { + "line": 9, + "column": 14, + "problem": "SpreadOperator", + "suggest": "", + "rule": "It is possible to spread only arrays into the rest parameter (arkts-no-spread)" + }, + { + "line": 11, + "column": 15, + "problem": "ObjectLiteralNoContextType", + "suggest": "", + "rule": "Object literal must correspond to some explicitly declared class or interface (arkts-no-untyped-obj-literals)" + }, + { + "line": 12, + "column": 15, + "problem": "ObjectLiteralNoContextType", + "suggest": "", + "rule": "Object literal must correspond to some explicitly declared class or interface (arkts-no-untyped-obj-literals)" + }, + { + "line": 12, + "column": 16, + "problem": "SpreadOperator", + "suggest": "", + "rule": "It is possible to spread only arrays into the rest parameter (arkts-no-spread)" + } + ] +} \ No newline at end of file diff --git a/linter/.gitignore b/linter/.gitignore index 4797db793..3feb73341 100644 --- a/linter/.gitignore +++ b/linter/.gitignore @@ -8,4 +8,5 @@ cookbook_convertor/md .vscode .cache test/**/results +test_rules/**/results package-lock.json \ No newline at end of file diff --git a/linter/package.json b/linter/package.json index be08a5e89..b9f16d7bf 100644 --- a/linter/package.json +++ b/linter/package.json @@ -16,8 +16,10 @@ "build": "npm run clean && npm run compile && npm run webpack && npm run pack:linter", "postinstall": "npm run build", "pack:linter": "rimraf bundle && mkdir bundle && npm pack --pack-destination bundle", - "test": "npm run compile && rimraf test/results && node build/src/TestRunner.js test", - "rule_tests": "npm run compile && rimraf test_rules/results && node build/src/TestRunner.js test_rules" + "test": "npm run compile && rimraf test/results test_rules/results && node build/src/TestRunner.js test test_rules", + "test_main": "npm run compile && rimraf test/results && node build/src/TestRunner.js test", + "test_rules": "npm run compile && rimraf test_rules/results && node build/src/TestRunner.js test_rules", + "update-tests": "node scripts/update-test-results.mjs test test_rules" }, "dependencies": { "typescript": "4.8.4", diff --git a/linter/test/update-test-results.bat b/linter/scripts/update-test-results.bat similarity index 100% rename from linter/test/update-test-results.bat rename to linter/scripts/update-test-results.bat diff --git a/linter/test/update-test-results.mjs b/linter/scripts/update-test-results.mjs similarity index 68% rename from linter/test/update-test-results.mjs rename to linter/scripts/update-test-results.mjs index b750c0706..dc579e424 100644 --- a/linter/test/update-test-results.mjs +++ b/linter/scripts/update-test-results.mjs @@ -34,8 +34,17 @@ const AUTOFIX_SKIP_EXT = '.autofix.skip'; const DIFF_EXT = '.diff'; const RESULTS_DIR = 'results' +let testDirs = []; + // forces to update all tests regardless of whether there was diff in a test result -const force_update = process.argv.includes('--force'); +const force_update = false; + +for (let arg of process.argv.slice(2)) { + if (arg === '--force') + force_update = true; + else + testDirs.push(arg); +} const DEFAULT_COPYRIGHT = [ "Copyright (c) 2023-2023 Huawei Device Co., Ltd.", @@ -61,25 +70,25 @@ function readTestFile(filePath) { } } -function updateTest(testFile, mode) { +function updateTest(testDir, testFile, mode) { let resultExt = RESULT_EXT[mode]; let testFileWithExt = testFile + resultExt; // Do not update autofix result if test is skipped - if (mode === Mode.AUTOFIX && fs.existsSync(testFile + AUTOFIX_SKIP_EXT)) { + if (mode === Mode.AUTOFIX && fs.existsSync(path.join(testDir, testFileWithExt + AUTOFIX_SKIP_EXT))) { return; } // Update test result when 'diff' exists or the 'force' option is enabled. - if (!fs.existsSync(path.join(RESULTS_DIR, testFileWithExt + DIFF_EXT)) && !force_update) { + if (!fs.existsSync(path.join(testDir, RESULTS_DIR, testFileWithExt + DIFF_EXT)) && !force_update) { return; } - let expectedResult = readTestFile(testFileWithExt); + let expectedResult = readTestFile(path.join(testDir, testFileWithExt)); const copyright = expectedResult?.copyright ?? DEFAULT_COPYRIGHT; - let actualResult = readTestFile(path.join(RESULTS_DIR, testFileWithExt)); + let actualResult = readTestFile(path.join(testDir, RESULTS_DIR, testFileWithExt)); if (!actualResult || !actualResult.nodes) { console.log(`Failed to update ${testFileWithExt}: couldn't read ACTUAL result file.`); return; @@ -87,28 +96,24 @@ function updateTest(testFile, mode) { // Write file with actual test results. let newResultJSON = JSON.stringify({ copyright, nodes: actualResult.nodes }, null, 4); - fs.writeFileSync(testFileWithExt, newResultJSON); + fs.writeFileSync(path.join(testDir, testFileWithExt), newResultJSON); console.log(`Updated ${testFileWithExt}`); } -if (!fs.existsSync(RESULTS_DIR)) { - console.log(`The ${RESULTS_DIR} dir does not exist!`); - process.exit(0); -} +for (let testDir of testDirs) { + if (!fs.existsSync(path.join(testDir, RESULTS_DIR))) continue; -// Get tests from test directory. -let testFiles = fs.readdirSync(".").filter(x => - (x.trimEnd().endsWith(TS_EXT) && !x.trimEnd().endsWith(D_TS_EXT)) || x.trimEnd().endsWith(TSX_EXT)); + // Get tests from test directory. + let testFiles = fs.readdirSync(testDir).filter(x => + (x.trimEnd().endsWith(TS_EXT) && !x.trimEnd().endsWith(D_TS_EXT)) || x.trimEnd().endsWith(TSX_EXT)); -if (!testFiles || testFiles.length == 0) { - console.log("No tests to update."); - process.exit(0); -} + if (!testFiles) continue; -// Update result for each test for Strict and Relax modes: -for (let testFile of testFiles) { - updateTest(testFile, Mode.RELAX); - updateTest(testFile, Mode.STRICT); - updateTest(testFile, Mode.AUTOFIX); + // Update result for each test for Strict and Relax modes: + for (let testFile of testFiles) { + updateTest(testDir, testFile, Mode.RELAX); + updateTest(testDir, testFile, Mode.STRICT); + updateTest(testDir, testFile, Mode.AUTOFIX); + } } \ No newline at end of file diff --git a/linter/test/update-test-results.sh b/linter/scripts/update-test-results.sh old mode 100755 new mode 100644 similarity index 100% rename from linter/test/update-test-results.sh rename to linter/scripts/update-test-results.sh diff --git a/linter/src/FaultAttrs.ts b/linter/src/FaultAttrs.ts index 51ee559c1..4370ec6c1 100644 --- a/linter/src/FaultAttrs.ts +++ b/linter/src/FaultAttrs.ts @@ -88,7 +88,6 @@ faultsAttrs[FaultID.ConstructorFuncs] = {cookBookRef: '106',}; faultsAttrs[FaultID.EnumMemberNonConstInit] = {cookBookRef: '111',}; faultsAttrs[FaultID.EnumMerging] = {cookBookRef: '113',}; faultsAttrs[FaultID.NamespaceAsObject] = {cookBookRef: '114',}; -faultsAttrs[FaultID.ClassAsObject] = {cookBookRef: '149',}; faultsAttrs[FaultID.NonDeclarationInNamespace] = {cookBookRef: '116',}; faultsAttrs[FaultID.ImportFromPath] = {cookBookRef: '119',}; faultsAttrs[FaultID.TypeOnlyImport] = {migratable: true, cookBookRef: '118',}; @@ -115,6 +114,7 @@ faultsAttrs[FaultID.LimitedStdLibApi] = {cookBookRef: '144',}; faultsAttrs[FaultID.StrictDiagnostic] = {cookBookRef: '145',}; faultsAttrs[FaultID.ErrorSuppression] = {cookBookRef: '146',}; faultsAttrs[FaultID.UnsupportedDecorators] = {cookBookRef: '148',}; +faultsAttrs[FaultID.ClassAsObject] = {cookBookRef: '149',}; faultsAttrs[FaultID.ImportAfterStatement] = {cookBookRef: '150',}; faultsAttrs[FaultID.EsObjectType] = {cookBookRef: '8'}; faultsAttrs[FaultID.EsObjectAssignment] = {cookBookRef: '8'}; diff --git a/linter/src/TestRunner.ts b/linter/src/TestRunner.ts index 2d8953ebf..68826cb62 100644 --- a/linter/src/TestRunner.ts +++ b/linter/src/TestRunner.ts @@ -52,7 +52,7 @@ const AUTOFIX_SKIP_EXT = '.autofix.skip'; const ARGS_CONFIG_EXT = '.args.json' const DIFF_EXT = '.diff'; -function runTests(baseDir: string): number { +function runTests(testDirs: string[]): number { let hasComparisonFailures = false; // Set the IDE mode manually to enable storing information @@ -60,37 +60,36 @@ function runTests(baseDir: string): number { TypeScriptLinter.ideMode = true; TypeScriptLinter.testMode = true; - // Get tests from test directory - const testDir = baseDir ?? TEST_DIR; - const testFiles: string[] = fs.readdirSync(testDir) - .filter((x) => (x.trimEnd().endsWith(ts.Extension.Ts) && !x.trimEnd().endsWith(ts.Extension.Dts)) || x.trimEnd().endsWith(ts.Extension.Tsx)); - - if (!testFiles || testFiles.length == 0) { - logger.info('No tests to run!'); - process.exit(0); - } - let passed = 0, failed = 0; - // Run each test in Strict, Autofix, and Relax mode: - for (const testFile of testFiles) { - if (runTest(testDir, testFile, Mode.STRICT)) { - failed++; - hasComparisonFailures = true; - } - else passed++; - - if (runTest(testDir, testFile, Mode.AUTOFIX)) { - failed++; - hasComparisonFailures = true; - } - else passed++; - - if (runTest(testDir, testFile, Mode.RELAX)) { - failed++; - hasComparisonFailures = true; + // Get tests from test directory + if (!testDirs?.length) testDirs = [ TEST_DIR ]; + for (const testDir of testDirs) { + let testFiles: string[] = fs.readdirSync(testDir) + .filter((x) => (x.trimEnd().endsWith(ts.Extension.Ts) && !x.trimEnd().endsWith(ts.Extension.Dts)) || x.trimEnd().endsWith(ts.Extension.Tsx)); + + logger.info(`\nProcessing "${testDir}" directory:\n`); + + // Run each test in Strict, Autofix, and Relax mode: + for (const testFile of testFiles) { + if (runTest(testDir, testFile, Mode.STRICT)) { + failed++; + hasComparisonFailures = true; + } + else passed++; + + if (runTest(testDir, testFile, Mode.AUTOFIX)) { + failed++; + hasComparisonFailures = true; + } + else passed++; + + if (runTest(testDir, testFile, Mode.RELAX)) { + failed++; + hasComparisonFailures = true; + } + else passed++; } - else passed++; } logger.info(`\nSUMMARY: ${passed + failed} total, ${passed} passed or skipped, ${failed} failed.`); @@ -241,4 +240,4 @@ ${actualNode}`; return diff; } -runTests(process.argv[2]); +runTests(process.argv.slice(2)); diff --git a/linter/src/utils/TsUtils.ts b/linter/src/utils/TsUtils.ts index 6aa0e7814..b532a1e80 100644 --- a/linter/src/utils/TsUtils.ts +++ b/linter/src/utils/TsUtils.ts @@ -949,15 +949,12 @@ export class TsUtils { if (type.isUnion()) { for (let compType of type.types) { - if (this.isLibraryType(compType)) { - return true; - } - - if (!isStdLibraryType(compType) && !isIntrinsicObjectType(compType) && !this.isAnyType(compType)) { - return false; + let isDynamic = this.isDynamicType(compType); + if (isDynamic || isDynamic === undefined) { + return isDynamic; } } - return undefined; + return false; } if (this.isLibraryType(type)) { diff --git a/linter/test/dynamic_lib.d.ts b/linter/test/dynamic_lib.d.ts index a9bb5c9a5..b6a9493cb 100644 --- a/linter/test/dynamic_lib.d.ts +++ b/linter/test/dynamic_lib.d.ts @@ -48,3 +48,24 @@ export let dynamic_array: Array; export declare class C1 {} export declare function f2(c: C1): void; + +export type Length = string | number | Resource; +export interface Resource { + readonly id: number; + readonly type: number; +} +export type Padding = { + top?: Length; + right?: Length; + bottom?: Length; + left?: Length; +} +export type Margin = Padding; +export interface Position { + x?: Length; + y?: Length; +} + +export function padding(value: Padding | Length): any; +export function margin(value: Margin | Length): any; +export function position(value: Position): any; \ No newline at end of file diff --git a/linter/test/dynamic_object_literals.ts b/linter/test/dynamic_object_literals.ts index 7ed1e3479..ea7f9759a 100644 --- a/linter/test/dynamic_object_literals.ts +++ b/linter/test/dynamic_object_literals.ts @@ -13,7 +13,19 @@ * limitations under the License. */ -import { I, foo, I2, I3, bar, C, getDynamicObject, dynamic_array } from "./dynamic_lib" +import { + I, + foo, + I2, + I3, + bar, + C, + getDynamicObject, + dynamic_array, + padding, + margin, + position +} from "./dynamic_lib" function main(): void { let obj: I = { @@ -67,4 +79,9 @@ function createInitProps(c: C) { } // #13483 - pass object literal to method call of exported variable -dynamic_array.splice(2, 0, {a: 1, b: '2'}); \ No newline at end of file +dynamic_array.splice(2, 0, {a: 1, b: '2'}); + +// #13550 - allow literals as property names in dynamic context +padding({'top': '0px', 'right': '5px', 'bottom': '10px', 'left': '15px'}); +margin({'top': '10px', 'right': '20px', 'bottom': '30px', 'left': '40px'}); +position({'x': '20', 'y': '40'}); \ No newline at end of file diff --git a/linter/test_rules/rule1.ts.autofix.json b/linter/test_rules/rule1.ts.autofix.json index ed9b9b05a..32a60bb65 100644 --- a/linter/test_rules/rule1.ts.autofix.json +++ b/linter/test_rules/rule1.ts.autofix.json @@ -1,4 +1,18 @@ { + "copyright": [ + "Copyright (c) 2023-2023 Huawei Device Co., Ltd.", + "Licensed under the Apache License, Version 2.0 (the 'License');", + "you may not use this file except in compliance with the License.", + "You may obtain a copy of the License at", + "", + "http://www.apache.org/licenses/LICENSE-2.0", + "", + "Unless required by applicable law or agreed to in writing, software", + "distributed under the License is distributed on an 'AS IS' BASIS,", + "WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.", + "See the License for the specific language governing permissions and", + "limitations under the License." + ], "nodes": [ { "line": 2, @@ -21,13 +35,6 @@ "column": 10, "problem": "LiteralAsPropertyName", "autofixable": true, - "autofix": [ - { - "replacementText": "name", - "start": 10, - "end": 16 - } - ], "suggest": "", "rule": "Objects with property names that are not identifiers are not supported (arkts-identifiers-as-prop-names)" }, @@ -36,13 +43,6 @@ "column": 21, "problem": "LiteralAsPropertyName", "autofixable": true, - "autofix": [ - { - "replacementText": "__2", - "start": 21, - "end": 22 - } - ], "suggest": "", "rule": "Objects with property names that are not identifiers are not supported (arkts-identifiers-as-prop-names)" }, @@ -51,13 +51,6 @@ "column": 13, "problem": "PropertyAccessByIndex", "autofixable": true, - "autofix": [ - { - "replacementText": "x.name", - "start": 40, - "end": 49 - } - ], "suggest": "", "rule": "Indexed access is not supported for fields (arkts-no-props-by-index)" }, @@ -66,13 +59,6 @@ "column": 13, "problem": "PropertyAccessByIndex", "autofixable": true, - "autofix": [ - { - "replacementText": "x.__2", - "start": 63, - "end": 67 - } - ], "suggest": "", "rule": "Indexed access is not supported for fields (arkts-no-props-by-index)" }, @@ -89,13 +75,6 @@ "column": 13, "problem": "PropertyAccessByIndex", "autofixable": true, - "autofix": [ - { - "replacementText": "y.__2", - "start": 179, - "end": 183 - } - ], "suggest": "", "rule": "Indexed access is not supported for fields (arkts-no-props-by-index)" } diff --git a/linter/test_rules/rule102.ts.autofix.json b/linter/test_rules/rule102.ts.autofix.json index cf4d6a275..e9faca40d 100644 --- a/linter/test_rules/rule102.ts.autofix.json +++ b/linter/test_rules/rule102.ts.autofix.json @@ -1,4 +1,18 @@ { + "copyright": [ + "Copyright (c) 2023-2023 Huawei Device Co., Ltd.", + "Licensed under the Apache License, Version 2.0 (the 'License');", + "you may not use this file except in compliance with the License.", + "You may obtain a copy of the License at", + "", + "http://www.apache.org/licenses/LICENSE-2.0", + "", + "Unless required by applicable law or agreed to in writing, software", + "distributed under the License is distributed on an 'AS IS' BASIS,", + "WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.", + "See the License for the specific language governing permissions and", + "limitations under the License." + ], "nodes": [ { "line": 1, @@ -38,7 +52,7 @@ "problem": "IntefaceExtendDifProps", "autofixable": false, "suggest": "", - "rule": "Interface declarations (extends same property) (arkts-no-extend-same-prop)" + "rule": "Interface can not extend interfaces with the same method (arkts-no-extend-same-prop)" }, { "line": 9, diff --git a/linter/test_rules/rule102.ts.relax.json b/linter/test_rules/rule102.ts.relax.json index a9b169620..40159bc31 100644 --- a/linter/test_rules/rule102.ts.relax.json +++ b/linter/test_rules/rule102.ts.relax.json @@ -1,4 +1,18 @@ { + "copyright": [ + "Copyright (c) 2023-2023 Huawei Device Co., Ltd.", + "Licensed under the Apache License, Version 2.0 (the 'License');", + "you may not use this file except in compliance with the License.", + "You may obtain a copy of the License at", + "", + "http://www.apache.org/licenses/LICENSE-2.0", + "", + "Unless required by applicable law or agreed to in writing, software", + "distributed under the License is distributed on an 'AS IS' BASIS,", + "WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.", + "See the License for the specific language governing permissions and", + "limitations under the License." + ], "nodes": [ { "line": 1, @@ -33,7 +47,7 @@ "column": 1, "problem": "IntefaceExtendDifProps", "suggest": "", - "rule": "Interface declarations (extends same property) (arkts-no-extend-same-prop)" + "rule": "Interface can not extend interfaces with the same method (arkts-no-extend-same-prop)" }, { "line": 9, diff --git a/linter/test_rules/rule102.ts.strict.json b/linter/test_rules/rule102.ts.strict.json index a9b169620..40159bc31 100644 --- a/linter/test_rules/rule102.ts.strict.json +++ b/linter/test_rules/rule102.ts.strict.json @@ -1,4 +1,18 @@ { + "copyright": [ + "Copyright (c) 2023-2023 Huawei Device Co., Ltd.", + "Licensed under the Apache License, Version 2.0 (the 'License');", + "you may not use this file except in compliance with the License.", + "You may obtain a copy of the License at", + "", + "http://www.apache.org/licenses/LICENSE-2.0", + "", + "Unless required by applicable law or agreed to in writing, software", + "distributed under the License is distributed on an 'AS IS' BASIS,", + "WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.", + "See the License for the specific language governing permissions and", + "limitations under the License." + ], "nodes": [ { "line": 1, @@ -33,7 +47,7 @@ "column": 1, "problem": "IntefaceExtendDifProps", "suggest": "", - "rule": "Interface declarations (extends same property) (arkts-no-extend-same-prop)" + "rule": "Interface can not extend interfaces with the same method (arkts-no-extend-same-prop)" }, { "line": 9, diff --git a/linter/test_rules/rule103.ts.autofix.json b/linter/test_rules/rule103.ts.autofix.json index 644a4887f..0b80e8ace 100644 --- a/linter/test_rules/rule103.ts.autofix.json +++ b/linter/test_rules/rule103.ts.autofix.json @@ -1,4 +1,18 @@ { + "copyright": [ + "Copyright (c) 2023-2023 Huawei Device Co., Ltd.", + "Licensed under the Apache License, Version 2.0 (the 'License');", + "you may not use this file except in compliance with the License.", + "You may obtain a copy of the License at", + "", + "http://www.apache.org/licenses/LICENSE-2.0", + "", + "Unless required by applicable law or agreed to in writing, software", + "distributed under the License is distributed on an 'AS IS' BASIS,", + "WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.", + "See the License for the specific language governing permissions and", + "limitations under the License." + ], "nodes": [ { "line": 1, @@ -14,7 +28,7 @@ "problem": "DeclWithDuplicateName", "autofixable": false, "suggest": "", - "rule": "Use unique names for types, namespaces, etc. (arkts-unique-names)" + "rule": "Use unique names for types and namespaces. (arkts-unique-names)" }, { "line": 2, @@ -38,7 +52,7 @@ "problem": "DeclWithDuplicateName", "autofixable": false, "suggest": "", - "rule": "Use unique names for types, namespaces, etc. (arkts-unique-names)" + "rule": "Use unique names for types and namespaces. (arkts-unique-names)" }, { "line": 9, @@ -54,7 +68,7 @@ "problem": "DeclWithDuplicateName", "autofixable": false, "suggest": "", - "rule": "Use unique names for types, namespaces, etc. (arkts-unique-names)" + "rule": "Use unique names for types and namespaces. (arkts-unique-names)" } ] } \ No newline at end of file diff --git a/linter/test_rules/rule103.ts.strict.json b/linter/test_rules/rule103.ts.strict.json index 0e46ba12f..ed74f56a2 100644 --- a/linter/test_rules/rule103.ts.strict.json +++ b/linter/test_rules/rule103.ts.strict.json @@ -1,4 +1,18 @@ { + "copyright": [ + "Copyright (c) 2023-2023 Huawei Device Co., Ltd.", + "Licensed under the Apache License, Version 2.0 (the 'License');", + "you may not use this file except in compliance with the License.", + "You may obtain a copy of the License at", + "", + "http://www.apache.org/licenses/LICENSE-2.0", + "", + "Unless required by applicable law or agreed to in writing, software", + "distributed under the License is distributed on an 'AS IS' BASIS,", + "WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.", + "See the License for the specific language governing permissions and", + "limitations under the License." + ], "nodes": [ { "line": 1, @@ -12,7 +26,7 @@ "column": 1, "problem": "DeclWithDuplicateName", "suggest": "", - "rule": "Use unique names for types, namespaces, etc. (arkts-unique-names)" + "rule": "Use unique names for types and namespaces. (arkts-unique-names)" }, { "line": 2, @@ -33,7 +47,7 @@ "column": 1, "problem": "DeclWithDuplicateName", "suggest": "", - "rule": "Use unique names for types, namespaces, etc. (arkts-unique-names)" + "rule": "Use unique names for types and namespaces. (arkts-unique-names)" }, { "line": 9, @@ -47,7 +61,7 @@ "column": 1, "problem": "DeclWithDuplicateName", "suggest": "", - "rule": "Use unique names for types, namespaces, etc. (arkts-unique-names)" + "rule": "Use unique names for types and namespaces. (arkts-unique-names)" } ] } \ No newline at end of file diff --git a/linter/test_rules/rule106.ts.autofix.json b/linter/test_rules/rule106.ts.autofix.json index c889e96a6..c9ee8bc8e 100644 --- a/linter/test_rules/rule106.ts.autofix.json +++ b/linter/test_rules/rule106.ts.autofix.json @@ -1,4 +1,18 @@ { + "copyright": [ + "Copyright (c) 2023-2023 Huawei Device Co., Ltd.", + "Licensed under the Apache License, Version 2.0 (the 'License');", + "you may not use this file except in compliance with the License.", + "You may obtain a copy of the License at", + "", + "http://www.apache.org/licenses/LICENSE-2.0", + "", + "Unless required by applicable law or agreed to in writing, software", + "distributed under the License is distributed on an 'AS IS' BASIS,", + "WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.", + "See the License for the specific language governing permissions and", + "limitations under the License." + ], "nodes": [ { "line": 7, @@ -13,7 +27,8 @@ "column": 29, "problem": "ClassAsObject", "autofixable": false, - "rule": "Classes cannot be used as objects (arkts-no-classes-as-objects)" + "suggest": "", + "rule": "Classes cannot be used as objects (arkts-no-classes-as-obj)" } ] } \ No newline at end of file diff --git a/linter/test_rules/rule106.ts.relax.json b/linter/test_rules/rule106.ts.relax.json index 501e2b9e4..9af8cdfaa 100644 --- a/linter/test_rules/rule106.ts.relax.json +++ b/linter/test_rules/rule106.ts.relax.json @@ -1,4 +1,18 @@ { + "copyright": [ + "Copyright (c) 2023-2023 Huawei Device Co., Ltd.", + "Licensed under the Apache License, Version 2.0 (the 'License');", + "you may not use this file except in compliance with the License.", + "You may obtain a copy of the License at", + "", + "http://www.apache.org/licenses/LICENSE-2.0", + "", + "Unless required by applicable law or agreed to in writing, software", + "distributed under the License is distributed on an 'AS IS' BASIS,", + "WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.", + "See the License for the specific language governing permissions and", + "limitations under the License." + ], "nodes": [ { "line": 7, @@ -11,7 +25,8 @@ "line": 14, "column": 29, "problem": "ClassAsObject", - "rule": "Classes cannot be used as objects (arkts-no-classes-as-objects)" + "suggest": "", + "rule": "Classes cannot be used as objects (arkts-no-classes-as-obj)" } ] } \ No newline at end of file diff --git a/linter/test_rules/rule106.ts.strict.json b/linter/test_rules/rule106.ts.strict.json index 501e2b9e4..9af8cdfaa 100644 --- a/linter/test_rules/rule106.ts.strict.json +++ b/linter/test_rules/rule106.ts.strict.json @@ -1,4 +1,18 @@ { + "copyright": [ + "Copyright (c) 2023-2023 Huawei Device Co., Ltd.", + "Licensed under the Apache License, Version 2.0 (the 'License');", + "you may not use this file except in compliance with the License.", + "You may obtain a copy of the License at", + "", + "http://www.apache.org/licenses/LICENSE-2.0", + "", + "Unless required by applicable law or agreed to in writing, software", + "distributed under the License is distributed on an 'AS IS' BASIS,", + "WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.", + "See the License for the specific language governing permissions and", + "limitations under the License." + ], "nodes": [ { "line": 7, @@ -11,7 +25,8 @@ "line": 14, "column": 29, "problem": "ClassAsObject", - "rule": "Classes cannot be used as objects (arkts-no-classes-as-objects)" + "suggest": "", + "rule": "Classes cannot be used as objects (arkts-no-classes-as-obj)" } ] } \ No newline at end of file diff --git a/linter/test_rules/rule139.ts.autofix.json b/linter/test_rules/rule139.ts.autofix.json index fdf87817e..889c717b6 100644 --- a/linter/test_rules/rule139.ts.autofix.json +++ b/linter/test_rules/rule139.ts.autofix.json @@ -1,4 +1,18 @@ { + "copyright": [ + "Copyright (c) 2023-2023 Huawei Device Co., Ltd.", + "Licensed under the Apache License, Version 2.0 (the 'License');", + "you may not use this file except in compliance with the License.", + "You may obtain a copy of the License at", + "", + "http://www.apache.org/licenses/LICENSE-2.0", + "", + "Unless required by applicable law or agreed to in writing, software", + "distributed under the License is distributed on an 'AS IS' BASIS,", + "WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.", + "See the License for the specific language governing permissions and", + "limitations under the License." + ], "nodes": [ { "line": 6, @@ -8,6 +22,14 @@ "suggest": "", "rule": "Use explicit types instead of \"any\", \"unknown\" (arkts-no-any-unknown)" }, + { + "line": 20, + "column": 1, + "problem": "MethodReassignment", + "autofixable": false, + "suggest": "", + "rule": "Reassigning object methods is not supported (arkts-no-method-reassignment)" + }, { "line": 20, "column": 1, diff --git a/linter/test_rules/rule139.ts.relax.json b/linter/test_rules/rule139.ts.relax.json index 17815b317..b7b7c9f37 100644 --- a/linter/test_rules/rule139.ts.relax.json +++ b/linter/test_rules/rule139.ts.relax.json @@ -1,4 +1,18 @@ { + "copyright": [ + "Copyright (c) 2023-2023 Huawei Device Co., Ltd.", + "Licensed under the Apache License, Version 2.0 (the 'License');", + "you may not use this file except in compliance with the License.", + "You may obtain a copy of the License at", + "", + "http://www.apache.org/licenses/LICENSE-2.0", + "", + "Unless required by applicable law or agreed to in writing, software", + "distributed under the License is distributed on an 'AS IS' BASIS,", + "WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.", + "See the License for the specific language governing permissions and", + "limitations under the License." + ], "nodes": [ { "line": 6, @@ -7,6 +21,13 @@ "suggest": "", "rule": "Use explicit types instead of \"any\", \"unknown\" (arkts-no-any-unknown)" }, + { + "line": 20, + "column": 1, + "problem": "MethodReassignment", + "suggest": "", + "rule": "Reassigning object methods is not supported (arkts-no-method-reassignment)" + }, { "line": 20, "column": 1, diff --git a/linter/test_rules/rule139.ts.strict.json b/linter/test_rules/rule139.ts.strict.json index b90af5917..29d461209 100644 --- a/linter/test_rules/rule139.ts.strict.json +++ b/linter/test_rules/rule139.ts.strict.json @@ -1,4 +1,18 @@ { + "copyright": [ + "Copyright (c) 2023-2023 Huawei Device Co., Ltd.", + "Licensed under the Apache License, Version 2.0 (the 'License');", + "you may not use this file except in compliance with the License.", + "You may obtain a copy of the License at", + "", + "http://www.apache.org/licenses/LICENSE-2.0", + "", + "Unless required by applicable law or agreed to in writing, software", + "distributed under the License is distributed on an 'AS IS' BASIS,", + "WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.", + "See the License for the specific language governing permissions and", + "limitations under the License." + ], "nodes": [ { "line": 6, @@ -7,6 +21,13 @@ "suggest": "", "rule": "Use explicit types instead of \"any\", \"unknown\" (arkts-no-any-unknown)" }, + { + "line": 20, + "column": 1, + "problem": "MethodReassignment", + "suggest": "", + "rule": "Reassigning object methods is not supported (arkts-no-method-reassignment)" + }, { "line": 20, "column": 1, diff --git a/linter/test_rules/rule140.ts.autofix.json b/linter/test_rules/rule140.ts.autofix.json index fdf87817e..889c717b6 100644 --- a/linter/test_rules/rule140.ts.autofix.json +++ b/linter/test_rules/rule140.ts.autofix.json @@ -1,4 +1,18 @@ { + "copyright": [ + "Copyright (c) 2023-2023 Huawei Device Co., Ltd.", + "Licensed under the Apache License, Version 2.0 (the 'License');", + "you may not use this file except in compliance with the License.", + "You may obtain a copy of the License at", + "", + "http://www.apache.org/licenses/LICENSE-2.0", + "", + "Unless required by applicable law or agreed to in writing, software", + "distributed under the License is distributed on an 'AS IS' BASIS,", + "WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.", + "See the License for the specific language governing permissions and", + "limitations under the License." + ], "nodes": [ { "line": 6, @@ -8,6 +22,14 @@ "suggest": "", "rule": "Use explicit types instead of \"any\", \"unknown\" (arkts-no-any-unknown)" }, + { + "line": 20, + "column": 1, + "problem": "MethodReassignment", + "autofixable": false, + "suggest": "", + "rule": "Reassigning object methods is not supported (arkts-no-method-reassignment)" + }, { "line": 20, "column": 1, diff --git a/linter/test_rules/rule140.ts.relax.json b/linter/test_rules/rule140.ts.relax.json index 17815b317..b7b7c9f37 100644 --- a/linter/test_rules/rule140.ts.relax.json +++ b/linter/test_rules/rule140.ts.relax.json @@ -1,4 +1,18 @@ { + "copyright": [ + "Copyright (c) 2023-2023 Huawei Device Co., Ltd.", + "Licensed under the Apache License, Version 2.0 (the 'License');", + "you may not use this file except in compliance with the License.", + "You may obtain a copy of the License at", + "", + "http://www.apache.org/licenses/LICENSE-2.0", + "", + "Unless required by applicable law or agreed to in writing, software", + "distributed under the License is distributed on an 'AS IS' BASIS,", + "WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.", + "See the License for the specific language governing permissions and", + "limitations under the License." + ], "nodes": [ { "line": 6, @@ -7,6 +21,13 @@ "suggest": "", "rule": "Use explicit types instead of \"any\", \"unknown\" (arkts-no-any-unknown)" }, + { + "line": 20, + "column": 1, + "problem": "MethodReassignment", + "suggest": "", + "rule": "Reassigning object methods is not supported (arkts-no-method-reassignment)" + }, { "line": 20, "column": 1, diff --git a/linter/test_rules/rule140.ts.strict.json b/linter/test_rules/rule140.ts.strict.json index b90af5917..29d461209 100644 --- a/linter/test_rules/rule140.ts.strict.json +++ b/linter/test_rules/rule140.ts.strict.json @@ -1,4 +1,18 @@ { + "copyright": [ + "Copyright (c) 2023-2023 Huawei Device Co., Ltd.", + "Licensed under the Apache License, Version 2.0 (the 'License');", + "you may not use this file except in compliance with the License.", + "You may obtain a copy of the License at", + "", + "http://www.apache.org/licenses/LICENSE-2.0", + "", + "Unless required by applicable law or agreed to in writing, software", + "distributed under the License is distributed on an 'AS IS' BASIS,", + "WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.", + "See the License for the specific language governing permissions and", + "limitations under the License." + ], "nodes": [ { "line": 6, @@ -7,6 +21,13 @@ "suggest": "", "rule": "Use explicit types instead of \"any\", \"unknown\" (arkts-no-any-unknown)" }, + { + "line": 20, + "column": 1, + "problem": "MethodReassignment", + "suggest": "", + "rule": "Reassigning object methods is not supported (arkts-no-method-reassignment)" + }, { "line": 20, "column": 1, diff --git a/linter/test_rules/rule147.ts.autofix.json b/linter/test_rules/rule147.ts.autofix.json index fb4872508..819d36d95 100644 --- a/linter/test_rules/rule147.ts.autofix.json +++ b/linter/test_rules/rule147.ts.autofix.json @@ -1,10 +1,25 @@ { + "copyright": [ + "Copyright (c) 2023-2023 Huawei Device Co., Ltd.", + "Licensed under the Apache License, Version 2.0 (the 'License');", + "you may not use this file except in compliance with the License.", + "You may obtain a copy of the License at", + "", + "http://www.apache.org/licenses/LICENSE-2.0", + "", + "Unless required by applicable law or agreed to in writing, software", + "distributed under the License is distributed on an 'AS IS' BASIS,", + "WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.", + "See the License for the specific language governing permissions and", + "limitations under the License." + ], "nodes": [ { "line": 7, "column": 5, "problem": "ImportAfterStatement", "autofixable": false, + "suggest": "", "rule": "\"import\" statements after other statements are not allowed (arkts-no-misplaced-imports)" }, { @@ -13,7 +28,7 @@ "problem": "DeclWithDuplicateName", "autofixable": false, "suggest": "", - "rule": "Use unique names for types, namespaces, etc. (arkts-unique-names)" + "rule": "Use unique names for types and namespaces. (arkts-unique-names)" } ] } \ No newline at end of file diff --git a/linter/test_rules/rule147.ts.strict.json b/linter/test_rules/rule147.ts.strict.json index 7ea8c2621..99874461d 100644 --- a/linter/test_rules/rule147.ts.strict.json +++ b/linter/test_rules/rule147.ts.strict.json @@ -1,9 +1,24 @@ { + "copyright": [ + "Copyright (c) 2023-2023 Huawei Device Co., Ltd.", + "Licensed under the Apache License, Version 2.0 (the 'License');", + "you may not use this file except in compliance with the License.", + "You may obtain a copy of the License at", + "", + "http://www.apache.org/licenses/LICENSE-2.0", + "", + "Unless required by applicable law or agreed to in writing, software", + "distributed under the License is distributed on an 'AS IS' BASIS,", + "WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.", + "See the License for the specific language governing permissions and", + "limitations under the License." + ], "nodes": [ { "line": 7, "column": 5, "problem": "ImportAfterStatement", + "suggest": "", "rule": "\"import\" statements after other statements are not allowed (arkts-no-misplaced-imports)" }, { @@ -11,7 +26,7 @@ "column": 14, "problem": "DeclWithDuplicateName", "suggest": "", - "rule": "Use unique names for types, namespaces, etc. (arkts-unique-names)" + "rule": "Use unique names for types and namespaces. (arkts-unique-names)" } ] } \ No newline at end of file diff --git a/linter/test_rules/rule17.ts.autofix.json b/linter/test_rules/rule17.ts.autofix.json index b86e0ccaf..dcd0bb1a1 100644 --- a/linter/test_rules/rule17.ts.autofix.json +++ b/linter/test_rules/rule17.ts.autofix.json @@ -1,4 +1,18 @@ { + "copyright": [ + "Copyright (c) 2023-2023 Huawei Device Co., Ltd.", + "Licensed under the Apache License, Version 2.0 (the 'License');", + "you may not use this file except in compliance with the License.", + "You may obtain a copy of the License at", + "", + "http://www.apache.org/licenses/LICENSE-2.0", + "", + "Unless required by applicable law or agreed to in writing, software", + "distributed under the License is distributed on an 'AS IS' BASIS,", + "WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.", + "See the License for the specific language governing permissions and", + "limitations under the License." + ], "nodes": [ { "line": 2, @@ -13,13 +27,6 @@ "column": 20, "problem": "PropertyAccessByIndex", "autofixable": true, - "autofix": [ - { - "replacementText": "myArray.__1", - "start": 192, - "end": 202 - } - ], "suggest": "", "rule": "Indexed access is not supported for fields (arkts-no-props-by-index)" } diff --git a/linter/test_rules/rule29.ts.autofix.json b/linter/test_rules/rule29.ts.autofix.json index 61c7ba87e..7ce06f06c 100644 --- a/linter/test_rules/rule29.ts.autofix.json +++ b/linter/test_rules/rule29.ts.autofix.json @@ -1,17 +1,24 @@ { + "copyright": [ + "Copyright (c) 2023-2023 Huawei Device Co., Ltd.", + "Licensed under the Apache License, Version 2.0 (the 'License');", + "you may not use this file except in compliance with the License.", + "You may obtain a copy of the License at", + "", + "http://www.apache.org/licenses/LICENSE-2.0", + "", + "Unless required by applicable law or agreed to in writing, software", + "distributed under the License is distributed on an 'AS IS' BASIS,", + "WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.", + "See the License for the specific language governing permissions and", + "limitations under the License." + ], "nodes": [ { "line": 3, "column": 9, "problem": "PropertyAccessByIndex", "autofixable": true, - "autofix": [ - { - "replacementText": "p.x", - "start": 79, - "end": 85 - } - ], "suggest": "", "rule": "Indexed access is not supported for fields (arkts-no-props-by-index)" } diff --git a/linter/test_rules/rule31.ts.autofix.json b/linter/test_rules/rule31.ts.autofix.json index 6257255e1..93738805a 100644 --- a/linter/test_rules/rule31.ts.autofix.json +++ b/linter/test_rules/rule31.ts.autofix.json @@ -1,4 +1,18 @@ { + "copyright": [ + "Copyright (c) 2023-2023 Huawei Device Co., Ltd.", + "Licensed under the Apache License, Version 2.0 (the 'License');", + "you may not use this file except in compliance with the License.", + "You may obtain a copy of the License at", + "", + "http://www.apache.org/licenses/LICENSE-2.0", + "", + "Unless required by applicable law or agreed to in writing, software", + "distributed under the License is distributed on an 'AS IS' BASIS,", + "WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.", + "See the License for the specific language governing permissions and", + "limitations under the License." + ], "nodes": [ { "line": 21, @@ -6,7 +20,7 @@ "problem": "StructuralIdentity", "autofixable": false, "suggest": "", - "rule": "Structural identity is not supported (arkts-no-structural-identity)" + "rule": "Structural typing is not supported (arkts-no-structural-typing)" }, { "line": 24, @@ -14,7 +28,7 @@ "problem": "StructuralIdentity", "autofixable": false, "suggest": "", - "rule": "Structural identity is not supported (arkts-no-structural-identity)" + "rule": "Structural typing is not supported (arkts-no-structural-typing)" } ] } \ No newline at end of file diff --git a/linter/test_rules/rule31.ts.relax.json b/linter/test_rules/rule31.ts.relax.json index a37441892..278f67e07 100644 --- a/linter/test_rules/rule31.ts.relax.json +++ b/linter/test_rules/rule31.ts.relax.json @@ -1,18 +1,32 @@ { + "copyright": [ + "Copyright (c) 2023-2023 Huawei Device Co., Ltd.", + "Licensed under the Apache License, Version 2.0 (the 'License');", + "you may not use this file except in compliance with the License.", + "You may obtain a copy of the License at", + "", + "http://www.apache.org/licenses/LICENSE-2.0", + "", + "Unless required by applicable law or agreed to in writing, software", + "distributed under the License is distributed on an 'AS IS' BASIS,", + "WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.", + "See the License for the specific language governing permissions and", + "limitations under the License." + ], "nodes": [ { "line": 21, "column": 1, "problem": "StructuralIdentity", "suggest": "", - "rule": "Structural identity is not supported (arkts-no-structural-identity)" + "rule": "Structural typing is not supported (arkts-no-structural-typing)" }, { "line": 24, "column": 1, "problem": "StructuralIdentity", "suggest": "", - "rule": "Structural identity is not supported (arkts-no-structural-identity)" + "rule": "Structural typing is not supported (arkts-no-structural-typing)" } ] } \ No newline at end of file diff --git a/linter/test_rules/rule31.ts.strict.json b/linter/test_rules/rule31.ts.strict.json index a37441892..278f67e07 100644 --- a/linter/test_rules/rule31.ts.strict.json +++ b/linter/test_rules/rule31.ts.strict.json @@ -1,18 +1,32 @@ { + "copyright": [ + "Copyright (c) 2023-2023 Huawei Device Co., Ltd.", + "Licensed under the Apache License, Version 2.0 (the 'License');", + "you may not use this file except in compliance with the License.", + "You may obtain a copy of the License at", + "", + "http://www.apache.org/licenses/LICENSE-2.0", + "", + "Unless required by applicable law or agreed to in writing, software", + "distributed under the License is distributed on an 'AS IS' BASIS,", + "WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.", + "See the License for the specific language governing permissions and", + "limitations under the License." + ], "nodes": [ { "line": 21, "column": 1, "problem": "StructuralIdentity", "suggest": "", - "rule": "Structural identity is not supported (arkts-no-structural-identity)" + "rule": "Structural typing is not supported (arkts-no-structural-typing)" }, { "line": 24, "column": 1, "problem": "StructuralIdentity", "suggest": "", - "rule": "Structural identity is not supported (arkts-no-structural-identity)" + "rule": "Structural typing is not supported (arkts-no-structural-typing)" } ] } \ No newline at end of file diff --git a/linter/test_rules/rule32.ts.autofix.json b/linter/test_rules/rule32.ts.autofix.json index 1c1802d5e..a932e2c69 100644 --- a/linter/test_rules/rule32.ts.autofix.json +++ b/linter/test_rules/rule32.ts.autofix.json @@ -1,4 +1,18 @@ { + "copyright": [ + "Copyright (c) 2023-2023 Huawei Device Co., Ltd.", + "Licensed under the Apache License, Version 2.0 (the 'License');", + "you may not use this file except in compliance with the License.", + "You may obtain a copy of the License at", + "", + "http://www.apache.org/licenses/LICENSE-2.0", + "", + "Unless required by applicable law or agreed to in writing, software", + "distributed under the License is distributed on an 'AS IS' BASIS,", + "WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.", + "See the License for the specific language governing permissions and", + "limitations under the License." + ], "nodes": [ { "line": 20, @@ -6,7 +20,7 @@ "problem": "StructuralIdentity", "autofixable": false, "suggest": "", - "rule": "Structural identity is not supported (arkts-no-structural-identity)" + "rule": "Structural typing is not supported (arkts-no-structural-typing)" }, { "line": 23, @@ -14,7 +28,7 @@ "problem": "StructuralIdentity", "autofixable": false, "suggest": "", - "rule": "Structural identity is not supported (arkts-no-structural-identity)" + "rule": "Structural typing is not supported (arkts-no-structural-typing)" } ] } \ No newline at end of file diff --git a/linter/test_rules/rule32.ts.relax.json b/linter/test_rules/rule32.ts.relax.json index 433020aca..6446311e9 100644 --- a/linter/test_rules/rule32.ts.relax.json +++ b/linter/test_rules/rule32.ts.relax.json @@ -1,18 +1,32 @@ { + "copyright": [ + "Copyright (c) 2023-2023 Huawei Device Co., Ltd.", + "Licensed under the Apache License, Version 2.0 (the 'License');", + "you may not use this file except in compliance with the License.", + "You may obtain a copy of the License at", + "", + "http://www.apache.org/licenses/LICENSE-2.0", + "", + "Unless required by applicable law or agreed to in writing, software", + "distributed under the License is distributed on an 'AS IS' BASIS,", + "WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.", + "See the License for the specific language governing permissions and", + "limitations under the License." + ], "nodes": [ { "line": 20, "column": 1, "problem": "StructuralIdentity", "suggest": "", - "rule": "Structural identity is not supported (arkts-no-structural-identity)" + "rule": "Structural typing is not supported (arkts-no-structural-typing)" }, { "line": 23, "column": 1, "problem": "StructuralIdentity", "suggest": "", - "rule": "Structural identity is not supported (arkts-no-structural-identity)" + "rule": "Structural typing is not supported (arkts-no-structural-typing)" } ] } \ No newline at end of file diff --git a/linter/test_rules/rule32.ts.strict.json b/linter/test_rules/rule32.ts.strict.json index 433020aca..6446311e9 100644 --- a/linter/test_rules/rule32.ts.strict.json +++ b/linter/test_rules/rule32.ts.strict.json @@ -1,18 +1,32 @@ { + "copyright": [ + "Copyright (c) 2023-2023 Huawei Device Co., Ltd.", + "Licensed under the Apache License, Version 2.0 (the 'License');", + "you may not use this file except in compliance with the License.", + "You may obtain a copy of the License at", + "", + "http://www.apache.org/licenses/LICENSE-2.0", + "", + "Unless required by applicable law or agreed to in writing, software", + "distributed under the License is distributed on an 'AS IS' BASIS,", + "WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.", + "See the License for the specific language governing permissions and", + "limitations under the License." + ], "nodes": [ { "line": 20, "column": 1, "problem": "StructuralIdentity", "suggest": "", - "rule": "Structural identity is not supported (arkts-no-structural-identity)" + "rule": "Structural typing is not supported (arkts-no-structural-typing)" }, { "line": 23, "column": 1, "problem": "StructuralIdentity", "suggest": "", - "rule": "Structural identity is not supported (arkts-no-structural-identity)" + "rule": "Structural typing is not supported (arkts-no-structural-typing)" } ] } \ No newline at end of file diff --git a/linter/test_rules/rule35.ts.autofix.json b/linter/test_rules/rule35.ts.autofix.json index 1bca487a8..b58aa1b18 100644 --- a/linter/test_rules/rule35.ts.autofix.json +++ b/linter/test_rules/rule35.ts.autofix.json @@ -1,4 +1,18 @@ { + "copyright": [ + "Copyright (c) 2023-2023 Huawei Device Co., Ltd.", + "Licensed under the Apache License, Version 2.0 (the 'License');", + "you may not use this file except in compliance with the License.", + "You may obtain a copy of the License at", + "", + "http://www.apache.org/licenses/LICENSE-2.0", + "", + "Unless required by applicable law or agreed to in writing, software", + "distributed under the License is distributed on an 'AS IS' BASIS,", + "WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.", + "See the License for the specific language governing permissions and", + "limitations under the License." + ], "nodes": [ { "line": 31, @@ -6,7 +20,7 @@ "problem": "StructuralIdentity", "autofixable": false, "suggest": "", - "rule": "Structural identity is not supported (arkts-no-structural-identity)" + "rule": "Structural typing is not supported (arkts-no-structural-typing)" } ] } \ No newline at end of file diff --git a/linter/test_rules/rule35.ts.relax.json b/linter/test_rules/rule35.ts.relax.json index aae7e0324..f2b48d95a 100644 --- a/linter/test_rules/rule35.ts.relax.json +++ b/linter/test_rules/rule35.ts.relax.json @@ -1,11 +1,25 @@ { + "copyright": [ + "Copyright (c) 2023-2023 Huawei Device Co., Ltd.", + "Licensed under the Apache License, Version 2.0 (the 'License');", + "you may not use this file except in compliance with the License.", + "You may obtain a copy of the License at", + "", + "http://www.apache.org/licenses/LICENSE-2.0", + "", + "Unless required by applicable law or agreed to in writing, software", + "distributed under the License is distributed on an 'AS IS' BASIS,", + "WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.", + "See the License for the specific language governing permissions and", + "limitations under the License." + ], "nodes": [ { "line": 31, "column": 5, "problem": "StructuralIdentity", "suggest": "", - "rule": "Structural identity is not supported (arkts-no-structural-identity)" + "rule": "Structural typing is not supported (arkts-no-structural-typing)" } ] } \ No newline at end of file diff --git a/linter/test_rules/rule35.ts.strict.json b/linter/test_rules/rule35.ts.strict.json index aae7e0324..f2b48d95a 100644 --- a/linter/test_rules/rule35.ts.strict.json +++ b/linter/test_rules/rule35.ts.strict.json @@ -1,11 +1,25 @@ { + "copyright": [ + "Copyright (c) 2023-2023 Huawei Device Co., Ltd.", + "Licensed under the Apache License, Version 2.0 (the 'License');", + "you may not use this file except in compliance with the License.", + "You may obtain a copy of the License at", + "", + "http://www.apache.org/licenses/LICENSE-2.0", + "", + "Unless required by applicable law or agreed to in writing, software", + "distributed under the License is distributed on an 'AS IS' BASIS,", + "WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.", + "See the License for the specific language governing permissions and", + "limitations under the License." + ], "nodes": [ { "line": 31, "column": 5, "problem": "StructuralIdentity", "suggest": "", - "rule": "Structural identity is not supported (arkts-no-structural-identity)" + "rule": "Structural typing is not supported (arkts-no-structural-typing)" } ] } \ No newline at end of file diff --git a/linter/test_rules/rule4.ts.autofix.json b/linter/test_rules/rule4.ts.autofix.json index ee484068a..ba15a33cf 100644 --- a/linter/test_rules/rule4.ts.autofix.json +++ b/linter/test_rules/rule4.ts.autofix.json @@ -1,4 +1,18 @@ { + "copyright": [ + "Copyright (c) 2023-2023 Huawei Device Co., Ltd.", + "Licensed under the Apache License, Version 2.0 (the 'License');", + "you may not use this file except in compliance with the License.", + "You may obtain a copy of the License at", + "", + "http://www.apache.org/licenses/LICENSE-2.0", + "", + "Unless required by applicable law or agreed to in writing, software", + "distributed under the License is distributed on an 'AS IS' BASIS,", + "WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.", + "See the License for the specific language governing permissions and", + "limitations under the License." + ], "nodes": [ { "line": 1, @@ -6,7 +20,7 @@ "problem": "DeclWithDuplicateName", "autofixable": false, "suggest": "", - "rule": "Use unique names for types, namespaces, etc. (arkts-unique-names)" + "rule": "Use unique names for types and namespaces. (arkts-unique-names)" }, { "line": 2, @@ -14,7 +28,7 @@ "problem": "DeclWithDuplicateName", "autofixable": false, "suggest": "", - "rule": "Use unique names for types, namespaces, etc. (arkts-unique-names)" + "rule": "Use unique names for types and namespaces. (arkts-unique-names)" } ] } \ No newline at end of file diff --git a/linter/test_rules/rule4.ts.strict.json b/linter/test_rules/rule4.ts.strict.json index ba18acad6..9dda4cf21 100644 --- a/linter/test_rules/rule4.ts.strict.json +++ b/linter/test_rules/rule4.ts.strict.json @@ -1,18 +1,32 @@ { + "copyright": [ + "Copyright (c) 2023-2023 Huawei Device Co., Ltd.", + "Licensed under the Apache License, Version 2.0 (the 'License');", + "you may not use this file except in compliance with the License.", + "You may obtain a copy of the License at", + "", + "http://www.apache.org/licenses/LICENSE-2.0", + "", + "Unless required by applicable law or agreed to in writing, software", + "distributed under the License is distributed on an 'AS IS' BASIS,", + "WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.", + "See the License for the specific language governing permissions and", + "limitations under the License." + ], "nodes": [ { "line": 1, "column": 5, "problem": "DeclWithDuplicateName", "suggest": "", - "rule": "Use unique names for types, namespaces, etc. (arkts-unique-names)" + "rule": "Use unique names for types and namespaces. (arkts-unique-names)" }, { "line": 2, "column": 1, "problem": "DeclWithDuplicateName", "suggest": "", - "rule": "Use unique names for types, namespaces, etc. (arkts-unique-names)" + "rule": "Use unique names for types and namespaces. (arkts-unique-names)" } ] } \ No newline at end of file diff --git a/linter/test_rules/rule52.ts.autofix.json b/linter/test_rules/rule52.ts.autofix.json index 4fc1a46af..d08778c75 100644 --- a/linter/test_rules/rule52.ts.autofix.json +++ b/linter/test_rules/rule52.ts.autofix.json @@ -1,4 +1,18 @@ { + "copyright": [ + "Copyright (c) 2023-2023 Huawei Device Co., Ltd.", + "Licensed under the Apache License, Version 2.0 (the 'License');", + "you may not use this file except in compliance with the License.", + "You may obtain a copy of the License at", + "", + "http://www.apache.org/licenses/LICENSE-2.0", + "", + "Unless required by applicable law or agreed to in writing, software", + "distributed under the License is distributed on an 'AS IS' BASIS,", + "WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.", + "See the License for the specific language governing permissions and", + "limitations under the License." + ], "nodes": [ { "line": 1, @@ -13,13 +27,6 @@ "column": 9, "problem": "PropertyAccessByIndex", "autofixable": true, - "autofix": [ - { - "replacementText": "person.name", - "start": 54, - "end": 68 - } - ], "suggest": "", "rule": "Indexed access is not supported for fields (arkts-no-props-by-index)" }, @@ -28,13 +35,6 @@ "column": 9, "problem": "PropertyAccessByIndex", "autofixable": true, - "autofix": [ - { - "replacementText": "person.isEmployee", - "start": 77, - "end": 97 - } - ], "suggest": "", "rule": "Indexed access is not supported for fields (arkts-no-props-by-index)" }, @@ -51,13 +51,6 @@ "column": 9, "problem": "PropertyAccessByIndex", "autofixable": true, - "autofix": [ - { - "replacementText": "person.office", - "start": 106, - "end": 122 - } - ], "suggest": "", "rule": "Indexed access is not supported for fields (arkts-no-props-by-index)" } -- Gitee