Syntax Warnings
1 The Syntax Warnings Reference
syntax-warning
syntax-warning?
syntax-warning/  fix?
syntax-warning-message
syntax-warning-stx
syntax-warning-kind
syntax-warning-fix
warning-kind?
define-warning-kind
warning-kind-name
syntax-warn
syntax-warnings
read-syntax-warnings
read-syntax-warnings/  file
warning-config?
warning-config-merge
empty-warning-config
suppress
unsuppress
filter-unsuppressed-warnings
2 The Syntax Warning Command Line Interface
2.1 raco warn:   Checking Syntax Warnings
2.2 raco fix:   Fixing Syntax Warnings
3 The Syntax Warnings Language
require
require:  phase-order
6.6

Syntax Warnings

This library includes forms and functions for working with syntax warnings. A syntax warning is a compile-time source code annotation meant to draw attention to potential defects. Syntax warnings can be used to point out bad code style, sub-optimal constructs, excessively verbose code, or use of deprecated features. Additionally included in this library are the raco warn and raco fix commands for finding and fixing warnings, and the #lang racket/base/warn language which provides many forms in racket/base with warnings attached in various ways.

Source code for this library is avaible at https://github.com/jackfirth/syntax-warn

This library is provided as several packages. These packages are organized as follows:

    1 The Syntax Warnings Reference

    2 The Syntax Warning Command Line Interface

      2.1 raco warn: Checking Syntax Warnings

      2.2 raco fix: Fixing Syntax Warnings

    3 The Syntax Warnings Language

1 The Syntax Warnings Reference

 (require syntax/warn)
  packages: syntax-warn, syntax-warn-base

This module defines the programmatic API for adding syntax warnings to syntax objects. Warnings added via this library can be detected and manipulated by the tools outlined in The Syntax Warning Command Line Interface.

procedure

(syntax-warning #:message message    
  #:stx stx    
  [#:kind kind    
  #:fix fix])  syntax-warning?
  message : string?
  stx : syntax?
  kind : warning-kind? = #f
  fix : syntax? = #f
Constructs a syntax warning of kind kind that identifies stx as the syntax to blame and fix as a suggested replacement to use in place of stx. If kind is not provided, the warning doesn’t declare itself as having a particular kind. If fix is not provided, the warning makes no suggestions about how to resolve it.

procedure

(syntax-warning? v)  boolean?

  v : any/c
Predicate that recognizes syntax warnings.

procedure

(syntax-warning/fix? v)  boolean?

  v : any/c
Predicate that recognizes syntax warnings that include a suggested fix.

procedure

(syntax-warning-message warning)  string?

  warning : syntax-warning?

procedure

(syntax-warning-stx warning)  syntax?

  warning : syntax-warning?

procedure

(syntax-warning-kind warning)  (or/c warning-kind? #f)

  warning : syntax-warning?

procedure

(syntax-warning-fix warning)  (or/c syntax? #f)

  warning : syntax-warning?
Accessors for fields of syntax warnings.

Predicate recognizing warning kinds.

Binds id as a warning kind, a value that can be used to classify similar warnings. The warning kind has a name, which is the quoted form of id. The raco warn tool uses warning kind names in its output.

procedure

(warning-kind-name kind)  symbol?

  kind : warning-kind?
Returns the name of kind.

procedure

(syntax-warn stx warning)  syntax?

  stx : syntax?
  warning : syntax-warning?
Returns a syntax object equivalent to stx, but with warning attached as a syntax warning. The syntax warning need not blame stx as the source of the problem, this procedure merely provides the ability to attach warnings to syntax objects via syntax properties.

Examples:
> (define-warning-kind identifier-capitalization-warning)
> (syntax-warn #'(foo Bar)
               (syntax-warning #:message "Don't capitalize the \"Bar\" identifier"
                               #:stx #'foo
                               #:kind identifier-capitalization-warning))

#<syntax:2:0 (foo Bar)>

procedure

(syntax-warnings stx)  (listof syntax?)

  stx : syntax?
Returns a list of all syntax warnings present in stx. This includes syntax warnings in any syntax objects nested within stx.

procedure

(read-syntax-warnings [#:input-port in 
  #:source-name source 
  #:namespace namespace]) 
  (listof syntax-warning?)
  in : input-port? = (current-input-port)
  source : any/c = (object-name in)
  namespace : namespace? = (current-namespace)
Constructs a syntax object from in using read-syntax, fully expands it using expand-syntax in namespace, and returns a list of all syntax warnings found in the fully expanded module.

procedure

(read-syntax-warnings/file filepath 
  [#:namespace namespace]) 
  (listof syntax-warning?)
  filepath : path-string?
  namespace : namespace? = (current-namespace)
Like read-syntax-warnings, but reads filepath as a module. Sets the current-directory to the directory part of filepath and uses filepath as the source name.

procedure

(warning-config? v)  boolean?

  v : any/c
Predicate that recognizes warning configurations, values used to control the behavior of tools that analyze syntax warnings. Configurations from different souces may be merged with warning-config-merge. Currently, warning configurations contain information about what kinds of warnings should be suppressed or unsuppressed (in the case of warnings that aren’t on by default). See suppress and unsuppress for details on how to construct these configurations.

procedure

(warning-config-merge config ...)  warning-config?

  config : warning-config?
Merges the given config values into a single warning configuration. In the case of more than one config attempting to suppress or unsuppress a warning kind, the rightmost configuration takes precedence. Merging any config with the empty-warning-config is equivalent to leaving the config unchanged. If no configurations are provided, returns empty-warning-config.

The empty warning config. Represents no changes from default behavior.

procedure

(suppress kind ...)  warning-config?

  kind : (or/c warning-kind? symbol?)

procedure

(unsuppress kind ...)  warning-config?

  kind : (or/c warning-kind? symbol?)
Constructs a warning configuration where warnings of each of the given kinds is either suppressed or unsuppressed, depending on the function called. Warnings may be suppressed using an explicit warning kind value or suppressed by a symbol representing the name of the warning kind to suppress. Symbols allow configuration sources to construct warning kind configs without access to the warning kind bindings. To suppress some warnings and unsuppress others, see warning-config-merge.

procedure

(filter-unsuppressed-warnings warnings 
  config) 
  (listof syntax-warning?)
  warnings : (listof syntax-warning?)
  config : warning-config?
Returns all the syntax warnings in warnings that are not suppressed according to config.

2 The Syntax Warning Command Line Interface

This document describes the raco warn and raco fix commands. This commands allow a programmer to check for syntax warnings and, where possible, automatically fix them. The two commands are designed to work together - when raco warn outputs no warnings, raco fix makes no changes to any modules. Additionally, both commands accept the same flags for specifying which modules to check.

2.1 raco warn: Checking Syntax Warnings

The raco warn command searches for syntax warnings in a specified set of modules. Any found warnings are displayed with a message, the offending source code, and a suggested fix (if present). If any warnings are found the command exits as a failure, making it suitable for use in continuous integration systems.

Not all warnings need cause a failure. The raco warn command allows certain warnings to be suppressed by configuration. For every module that raco warn examines, the command looks for a warning configuration value named config provided by that module’s 'warning-config submodule. If this module or the expected binding isn’t present, empty-warning-config is used. This allows for per-module suppression of particular kinds of warnings, see the documentation of warning-config for details. Warnings may also be suppressed via command line flags.

The raco warn command accepts any number of arguments along with the following flags:

2.2 raco fix: Fixing Syntax Warnings

The raco fix command searches for syntax warnings in a specified set of modules and fixes them, if possible. For each module checked, the set of warnings is filtered to only warnings with suggested fixes that won’t interfere with each other. For instance, if two warnings suggest changing the same piece of code, raco fix will either fix one of the warnings if its affected source code fully encompasses the other warning’s source code, or fix neither warning if they only partially overlap. The raco fix command also accepts a run mode argument that can configure how raco fix applies changes, if at all.

The raco fix command accepts any number of arguments along with the following flags:

In addition, the raco fix command looks for warning configuration in the same way as raco warn with the same flags to control this behavior. Warnings can also be suppressed and unsuppressed with direct flags in the same manner as raco warn.

3 The Syntax Warnings Language

 (require racket/base/warn)
  packages: syntax-warn, syntax-warn-lang

This library provides a variant of the racket/base language that adds syntax warning wrappers around various forms. For example, the require binding introduced by this language enforces a few "good style" practices around require clauses.

When racket/base/warn is used as a #lang language, everything from racket/base is provided. Various forms are adjusted to attach syntax warnings in certain cases. Warning kinds for these warnings are also exported.

syntax

(require require-spec ...)

Like in racket/base, but warns require:phase-order when the given require-spec forms are not in phase order. Phase order is for-syntax first, for-template second, for-label third, for-meta fourth, and all other forms fifth.

value

require:phase-order : warning-kind?

A warning kind for when require clauses are not phase ordered.