Skip to content

Commit 6e0c06f

Browse files
authored
fix #13218: avoid some irrelevant warnings for nim doc,rst2html,--app:lib, + other fixes (#13550)
* fix #13218: avoid some irrelevant warnings for nim doc,rst2html * suppress warnRedefinitionOfLabel for nim doc * lots of fixes for UnusedImport warnings
1 parent 380a505 commit 6e0c06f

File tree

11 files changed

+27
-12
lines changed

11 files changed

+27
-12
lines changed

compiler/main.nim

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -225,6 +225,12 @@ proc mainCommand*(graph: ModuleGraph) =
225225
loadConfigs(DocConfig, cache, conf)
226226
commandDoc(cache, conf)
227227
of "doc2", "doc":
228+
conf.setNoteDefaults(warnLockLevel, false) # issue #13218
229+
conf.setNoteDefaults(warnRedefinitionOfLabel, false) # issue #13218
230+
# because currently generates lots of false positives due to conflation
231+
# of labels links in doc comments, eg for random.rand:
232+
# ## * `rand proc<#rand,Rand,Natural>`_ that returns an integer
233+
# ## * `rand proc<#rand,Rand,range[]>`_ that returns a float
228234
when defined(leanCompiler):
229235
quit "compiler wasn't built with documentation generator"
230236
else:
@@ -233,6 +239,7 @@ proc mainCommand*(graph: ModuleGraph) =
233239
defineSymbol(conf.symbols, "nimdoc")
234240
commandDoc2(graph, false)
235241
of "rst2html":
242+
conf.setNoteDefaults(warnRedefinitionOfLabel, false) # similar to issue #13218
236243
when defined(leanCompiler):
237244
quit "compiler wasn't built with documentation generator"
238245
else:

compiler/options.nim

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -289,7 +289,15 @@ type
289289
severity: Severity) {.closure, gcsafe.}
290290
cppCustomNamespace*: string
291291

292+
proc setNoteDefaults*(conf: ConfigRef, note: TNoteKind, enabled = true) =
293+
template fun(op) =
294+
conf.notes.op note
295+
conf.mainPackageNotes.op note
296+
conf.foreignPackageNotes.op note
297+
if enabled: fun(incl) else: fun(excl)
298+
292299
proc setNote*(conf: ConfigRef, note: TNoteKind, enabled = true) =
300+
# see also `prepareConfigNotes` which sets notes
293301
if note notin conf.cmdlineNotes:
294302
if enabled: incl(conf.notes, note) else: excl(conf.notes, note)
295303

doc/docgen_sample.nim

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,9 @@ import strutils
44

55
proc helloWorld*(times: int) =
66
## Takes an integer and outputs
7-
## as many "hello world!"s
7+
## as many indented "hello world!"s
88

99
for i in 0 .. times-1:
10-
echo "hello world!"
10+
echo "hello world!".indent(2) # using indent to avoid `UnusedImport`
1111

1212
helloWorld(5)

lib/impure/rdstdin.nim

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ elif defined(genode):
4343
stdin.readLine(line)
4444

4545
else:
46-
import linenoise, termios
46+
import linenoise
4747

4848
proc readLineFromStdin*(prompt: string): TaintedString {.
4949
tags: [ReadIOEffect, WriteIOEffect].} =

lib/pure/asyncdispatch.nim

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -168,7 +168,7 @@
168168

169169
include "system/inclrtl"
170170

171-
import os, tables, strutils, times, heapqueue, lists, options, asyncstreams
171+
import os, tables, strutils, times, heapqueue, options, asyncstreams
172172
import options, math, std/monotimes
173173
import asyncfutures except callSoon
174174

lib/pure/asynchttpserver.nim

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@
3030
##
3131
## waitFor server.serve(Port(8080), cb)
3232

33-
import tables, asyncnet, asyncdispatch, parseutils, uri, strutils
33+
import asyncnet, asyncdispatch, parseutils, uri, strutils
3434
import httpcore
3535

3636
export httpcore except parseHeader

lib/pure/encodings.nim

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
## Converts between different character encodings. On UNIX, this uses
1111
## the `iconv`:idx: library, on Windows the Windows API.
1212

13-
import os, parseutils, strutils
13+
import os
1414

1515
when not defined(windows):
1616
type
@@ -28,6 +28,7 @@ type
2828
## for encoding errors
2929

3030
when defined(windows):
31+
import parseutils, strutils
3132
proc eqEncodingNames(a, b: string): bool =
3233
var i = 0
3334
var j = 0

lib/pure/lenientops.nim

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,8 +24,6 @@
2424
## either casting to float or rounding to int might be preferred, and users
2525
## should make an explicit choice.
2626

27-
import typetraits
28-
2927
proc `+`*[I: SomeInteger, F: SomeFloat](i: I, f: F): F {.noSideEffect, inline.} =
3028
F(i) + f
3129
proc `+`*[I: SomeInteger, F: SomeFloat](f: F, i: I): F {.noSideEffect, inline.} =

lib/pure/selectors.nim

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@
2727
##
2828
## TODO: ``/dev/poll``, ``event ports`` and filesystem events.
2929

30-
import os, strutils, nativesockets
30+
import os, nativesockets
3131

3232
const hasThreadSupport = compileOption("threads") and defined(threadsafe)
3333

@@ -230,6 +230,7 @@ when defined(nimdoc):
230230
## For *poll* and *select* selectors ``-1`` is returned.
231231

232232
else:
233+
import strutils
233234
when hasThreadSupport:
234235
import locks
235236

lib/pure/strformat.nim

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -744,8 +744,6 @@ when isMainModule:
744744
check &"{high(int64)}", "9223372036854775807"
745745
check &"{low(int64)}", "-9223372036854775808"
746746

747-
import json
748-
749747
doAssert fmt"{'a'} {'b'}" == "a b"
750748

751749
echo("All tests ok")

0 commit comments

Comments
 (0)