eslint-config-nodejs-pmb 0.3.0 → 0.3.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/package.json CHANGED
@@ -1,5 +1,5 @@
1
1
  { "name": "eslint-config-nodejs-pmb",
2
- "version": "0.3.0",
2
+ "version": "0.3.1",
3
3
  "description": "My favorite eslint rules",
4
4
  "keywords": [],
5
5
 
@@ -10,16 +10,33 @@ function addfexts () {
10
10
  exec < <(eslint --ext js,mjs . | sed -urf <(echo '
11
11
  s~^ *([0-9]+):[0-9]+ +error +Missing file extension "(\S+)" for "(\S+|$\
12
12
  )" +import/extensions$~!:missfext \2 \3 \1~
13
+ s~^ *1:1 +error +Use the global form of \x27use strict\x27 strict$|$\
14
+ ~!global_use_strict~
13
15
  ')) || return $?
14
- local LN= SRC_FN=
16
+ local ABS_PWD="$(readlink -m .)"
17
+ local LN=
18
+ local SRC_FN=
19
+ local ERR_CNT_IN_FILE=
15
20
  while IFS= read -r LN; do
16
21
  case "$LN" in
17
22
  '' ) continue;;
18
- /*.mjs ) SRC_FN="$LN"; continue;;
23
+ /*.js | \
24
+ /*.mjs )
25
+ LN="${LN#"$ABS_PWD/"}"
26
+ SRC_FN="$LN"
27
+ ERR_CNT_IN_FILE=0
28
+ continue;;
19
29
  '!:missfext '* )
20
30
  LN="${LN#*:}"
21
31
  fix_"${LN%% *}" "${LN#* }" || return $?;;
22
- * ) echo "W: eslint says: '$LN'" >&2;;
32
+ !global_use_strict )
33
+ LANG=C sed -re '1s~^(\xEF\xBB\xBF|)~&\x27use strict\x27;\n~' \
34
+ -i -- "$SRC_FN" || return $?;;
35
+ * )
36
+ [ "$ERR_CNT_IN_FILE" == 0 ] && echo "W: In file '$SRC_FN':" >&2
37
+ (( ERR_CNT_IN_FILE += 1 ))
38
+ echo "W: eslint says: '$LN'" >&2
39
+ ;;
23
40
  esac
24
41
  done
25
42
  }
@@ -30,8 +47,13 @@ function fix_missfext () {
30
47
  local FEXT="${ARG%% *}"; ARG="${ARG#* }"
31
48
  local REF="${ARG%% *}"; ARG="${ARG#* }"
32
49
  local LNUM="$ARG"
33
- echo "D: Add fext .$FEXT to $SRC_FN line $LNUM:"
34
- sed -re "$LNUM"'s~(\x27|\x22);?$~.'"$FEXT"'&~' -i -- "$SRC_FN" || return $?
50
+ echo "D: Add fext .$FEXT to file '$SRC_FN' line $LNUM:"
51
+ local SED=(
52
+ sed -re
53
+ "$LNUM"'s~(\x27|\x22)\)?;?$~.'"$FEXT"'&~'
54
+ -i -- "$SRC_FN"
55
+ )
56
+ "${SED[@]}" || return $?$(echo "W: sed failed, rv=$?" >&2)
35
57
  }
36
58
 
37
59