aboutsummaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorCalvin Rose <calsrose@gmail.com>2021-05-31 16:51:14 -0500
committerCalvin Rose <calsrose@gmail.com>2021-05-31 16:51:53 -0500
commit2eadb21eb771449a2f75d3180ec6fb8e3cfb9ab0 (patch)
tree8ec7a0e0851b5e161718b64706137d27460b8f3f
parentMerge pull request #707 from pepe/fix-shadow (diff)
Update changelog.
-rw-r--r--CHANGELOG.md13
-rw-r--r--janet.115
-rw-r--r--src/boot/boot.janet41
3 files changed, 59 insertions, 10 deletions
diff --git a/CHANGELOG.md b/CHANGELOG.md
index 2393dcf9..03d36036 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -1,6 +1,19 @@
# Changelog
All notable changes to this project will be documented in this file.
+## 1.16.1 - ???
+- Add `maclintf` - a utility for adding linting messages when inside macros.
+- Print source code of offending line on compiler warnings and errors.
+- Fix some issues with linting and re-add missing `make docs`.
+- Allow controlling linting with dynamic bindings `:lint-warn`, `:lint-error`, and `:lint-levels`.
+- Add `-w` and `-x` command line flags to the `janet` binary to set linting thresholds.
+ linting thresholds are as follows:
+ - :none - will never be trigger.
+ - :relaxed - will only trigger on `:relaxed` lints.
+ - :normal - will trigger on `:relaxed` and `:normal` lints.
+ - :strict - will trigger on `:strict`, `:normal`, and `:relaxed` lints. This will catch the most issues
+ but can be distracting.
+
## 1.16.0 - 2021-05-30
- Add color documentation to the `doc` macro - enable/disable with `(dyn :doc-color)`.
- Remove simpler HTML docs from distribution - use website or built-in documentation instead.
diff --git a/janet.1 b/janet.1
index 1a9d5faa..448a8ae5 100644
--- a/janet.1
+++ b/janet.1
@@ -8,6 +8,8 @@ janet \- run the Janet language abstract machine
[\fB\-l\fR \fIMODULE\fR]
[\fB\-m\fR \fIPATH\fR]
[\fB\-c\fR \fIMODULE JIMAGE\fR]
+[\fB\-w\fR \fILEVEL\fR]
+[\fB\-x\fR \fILEVEL\fR]
[\fB\-\-\fR]
.BR script
.BR args ...
@@ -210,7 +212,18 @@ resulting image. Output should usually end with the .jimage extension.
Import a Janet module before running a script or repl. Multiple files can be loaded
in this manner, and exports from each file will be made available to the script
or repl.
-
+.TP
+.BR \-w\ level
+Set the warning linting level for Janet.
+This linting level should be one of :relaxed, :none, :strict, :normal, or a
+Janet number. Any linting message that is of a greater lint level than this setting will be displayed as
+a warning, but not stop compilation or execution.
+.TP
+.BR \-x\ level
+Set the error linting level for Janet.
+This linting level should be one of :relaxed, :none, :strict, :normal, or a
+Janet number. Any linting message that is of a greater lint level will cause a compilation error
+and stop compilation.
.TP
.BR \-\-
Stop parsing command line arguments. All arguments after this one will be considered file names
diff --git a/src/boot/boot.janet b/src/boot/boot.janet
index 0eed39c8..0cdf71e9 100644
--- a/src/boot/boot.janet
+++ b/src/boot/boot.janet
@@ -1784,6 +1784,20 @@
###
###
+(defn maclintf
+ ``When inside a macro, call this function to add a linter warning. Takes
+ a `fmt` argument like `string/format` which is used to format the message.``
+ [level fmt & args]
+ (def lints (dyn :macro-lints))
+ (when lints
+ (def form (dyn :macro-form))
+ (def [l c] (if (tuple? form) (tuple/sourcemap form) [nil nil]))
+ (def l (if-not (= -1 l) l))
+ (def c (if-not (= -1 c) c))
+ (def msg (string/format fmt ;args))
+ (array/push lints [level l c msg]))
+ nil)
+
(defn macex1
``Expand macros in a form, but do not recursively expand macros.
See `macex` docs for info on on-binding.``
@@ -2129,8 +2143,9 @@
col
": compile warning (" level "): ")
(eprint msg)
- (print-line-col where line col)
- (if ec (eprin "\e[0m"))
+ (when ec
+ (print-line-col where line col)
+ (eprin "\e[0m"))
(eflush))
(defn bad-compile
@@ -2148,8 +2163,9 @@
(if macrof
(debug/stacktrace macrof msg)
(eprint msg))
- (print-line-col where line col)
- (if ec (eprin "\e[0m"))
+ (when ec
+ (print-line-col where line col)
+ (eprin "\e[0m"))
(eflush))
(defn curenv
@@ -2164,7 +2180,8 @@
{:none 0
:relaxed 1
:normal 2
- :strict 3})
+ :strict 3
+ :all math/inf})
(defn run-context
```
@@ -2226,10 +2243,11 @@
(def res (compile source env where lints))
(unless (empty? lints)
# Convert lint levels to numbers.
+ (def levels (get env :lint-levels lint-levels))
(def lint-error (get env :lint-error))
(def lint-warning (get env :lint-warn))
- (def lint-error (or (get lint-levels lint-error lint-error) 0))
- (def lint-warning (or (get lint-levels lint-warning lint-warning) 2))
+ (def lint-error (or (get levels lint-error lint-error) 0))
+ (def lint-warning (or (get levels lint-warning lint-warning) 2))
(each [level line col msg] lints
(def lvl (get lint-levels level 0))
(cond
@@ -3455,6 +3473,11 @@
(if-let [jp (getenv-alias "JANET_HEADERPATH")] (setdyn :headerpath jp))
(if-let [jprofile (getenv-alias "JANET_PROFILE")] (setdyn :profilepath jprofile))
+ (defn- get-lint-level
+ [i]
+ (def x (in args (+ i 1)))
+ (or (scan-number x) (keyword x)))
+
# Flag handlers
(def handlers
{"h" (fn [&]
@@ -3505,8 +3528,8 @@
(eval-string (in args (+ i 1)))
2)
"d" (fn [&] (set *debug* true) 1)
- "w" (fn [i &] (set *warn-level* (keyword (in args (+ i 1)))) 2)
- "x" (fn [i &] (set *error-level* (keyword (in args (+ i 1)))) 2)
+ "w" (fn [i &] (set *warn-level* (get-lint-level i)) 2)
+ "x" (fn [i &] (set *error-level* (get-lint-level i)) 2)
"R" (fn [&] (setdyn :profilepath nil) 1)})
(defn- dohandler [n i &]