1
0
Fork 0
mirror of git://git.code.sf.net/p/cdesktopenv/code synced 2025-03-09 15:50:02 +00:00

Port illumos' shell linter improvements (#353)

This commit ports over two improvements to the shell linter from
illumos (original patch written by Andy Fiddaman). Links to the
relevant bug reports and the original patch:
https://www.illumos.org/issues/13601
https://www.illumos.org/issues/13631
c7b656fc71

The first improvement is to the lint warning for arithmetic
operators in [[ ... ]]. The ksh linter now suggests the correct
equivalent operator to use in ((...)). Example:
  $ ksh -nc '[[ 30 -gt 25 ]]'
  # Original warning
  warning: line 1: -gt within [[ ... ]] obsolete, use ((...))
  # New warning
  warning: line 1: [[ ... -gt ... ]] obsolete, use ((... > ...))

The second improvement pertains to variable expansion in arithmetic
expressions. The ksh linter now suggests referencing variable names
directly:
  $ ksh -nc 'integer foo=40; (($foo < 50 ))'
  # Old warning
  warning: line 1: variable expansion makes arithmetic evaluation less efficient
  # New warning
  warning: line 1: in '(($foo < 50))', using '$' is slower and can introduce rounding errors

src/cmd/ksh93/{data/lexstates,sh/lex,sh/parse}.c:
- Port the improved shell lint warnings from illumos to ksh93u+m.
- The original checks for arithmetic operators involved a bunch of
  if statements with inefficient calls to strcmp(3). These were
  replaced with a more efficient switch statement that avoids
  strcmp.
This commit is contained in:
Johnothan King 2021-11-30 12:26:17 -08:00 committed by Martijn Dekker
parent 370440473e
commit 6904585f49
4 changed files with 32 additions and 4 deletions

3
NEWS
View file

@ -13,6 +13,9 @@ Any uppercase BUG_* names are modernish shell bug IDs.
- Fixed a crash that could occur when a KEYBD trap was set and a multi-line
command substitution was input in an interactive shell.
- The shell linter's warnings for obsolete arithmetic operators in [[ ... ]]
and unnecessary variable expansion in ((...)) have been improved.
2021-11-24:
- The --posix mode was amended to stop the '.' command (but not 'source') from