From 31fe32afd11e2a638e954e42b6e21607efbbdc26 Mon Sep 17 00:00:00 2001 From: ringabout <43030857+ringabout@users.noreply.github.com> Date: Thu, 22 Sep 2022 03:04:33 +0800 Subject: [PATCH] fixes #20397; fixes stylecheck regression (#20398) * fixes #20397; fixes stylecheck * add testcase (cherry picked from commit 70c25c45d61926beca789fda0e57a10cbeef81e3) --- compiler/linter.nim | 1 + tests/stylecheck/t20397.nim | 4 ++++ tests/stylecheck/t20397_1.nim | 8 ++++++++ tests/stylecheck/t20397_2.nim | 7 +++++++ 4 files changed, 20 insertions(+) create mode 100644 tests/stylecheck/t20397.nim create mode 100644 tests/stylecheck/t20397_1.nim create mode 100644 tests/stylecheck/t20397_2.nim diff --git a/compiler/linter.nim b/compiler/linter.nim index 2c0ad4d6f4..0c2aaef792 100644 --- a/compiler/linter.nim +++ b/compiler/linter.nim @@ -93,6 +93,7 @@ proc nep1CheckDefImpl(conf: ConfigRef; info: TLineInfo; s: PSym; k: TSymKind) = template styleCheckDef*(ctx: PContext; info: TLineInfo; sym: PSym; k: TSymKind) = ## Check symbol definitions adhere to NEP1 style rules. if optStyleCheck in ctx.config.options and # ignore if styleChecks are off + {optStyleHint, optStyleError} * ctx.config.globalOptions != {} and # check only if hint/error is enabled hintName in ctx.config.notes and # ignore if name checks are not requested ctx.config.belongsToProjectPackage(ctx.module) and # ignore foreign packages optStyleUsages notin ctx.config.globalOptions and # ignore if requested to only check name usage diff --git a/tests/stylecheck/t20397.nim b/tests/stylecheck/t20397.nim new file mode 100644 index 0000000000..486a97d73e --- /dev/null +++ b/tests/stylecheck/t20397.nim @@ -0,0 +1,4 @@ +{.hintAsError[Name]:on.} +var a_b = 1 +discard a_b +{.hintAsError[Name]:off.} \ No newline at end of file diff --git a/tests/stylecheck/t20397_1.nim b/tests/stylecheck/t20397_1.nim new file mode 100644 index 0000000000..24f5791f89 --- /dev/null +++ b/tests/stylecheck/t20397_1.nim @@ -0,0 +1,8 @@ +discard """ + matrix: "--styleCheck:off" +""" + +{.hintAsError[Name]:on.} +var a_b = 1 +discard a_b +{.hintAsError[Name]:off.} \ No newline at end of file diff --git a/tests/stylecheck/t20397_2.nim b/tests/stylecheck/t20397_2.nim new file mode 100644 index 0000000000..3b8e1c4d64 --- /dev/null +++ b/tests/stylecheck/t20397_2.nim @@ -0,0 +1,7 @@ +discard """ + errormsg: "'a_b' should be: 'aB'" + matrix: "--styleCheck:error" +""" + +var a_b = 1 +discard a_b \ No newline at end of file