eslint-config-nodejs-pmb 0.2.7 → 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.
@@ -24,6 +24,7 @@ jobs:
24
24
  with:
25
25
  node-version: ${{ matrix.node-version }}
26
26
  - run: npm install .
27
+ - run: npm audit
27
28
  - run: npm test
28
29
 
29
30
 
package/package.json CHANGED
@@ -1,5 +1,5 @@
1
1
  { "name": "eslint-config-nodejs-pmb",
2
- "version": "0.2.7",
2
+ "version": "0.3.1",
3
3
  "description": "My favorite eslint rules",
4
4
  "keywords": [],
5
5
 
@@ -27,14 +27,14 @@
27
27
  },
28
28
  "devDependencies": {
29
29
  "absdir": "^1.0.6",
30
- "eslint-plugin-json-light": "^1.0.3",
30
+ "eslint-plugin-json-light-pmb": "^1.0.4",
31
31
  "eslint-plugin-node": "^11.1.0",
32
32
  "p-fatal": "^0.1.3",
33
33
  "safe-sortedjson": "^1.0.6",
34
34
  "usnam-pmb": "^0.2.5"
35
35
  },
36
36
  "peerDependencies": {
37
- "eslint": "^8.10.0"
37
+ "eslint": "^8.11.0"
38
38
  },
39
39
 
40
40
  "npm vs. BOM = Unexpected token": "-*- coding: UTF-8 -*-"
package/rules.js CHANGED
@@ -73,6 +73,21 @@ const rules = {
73
73
  };
74
74
 
75
75
 
76
+ const overrides = [
77
+ { files: ['**.js'], parserOptions: { sourceType: 'script' } },
78
+ { files: ['**.mjs'],
79
+ rules: {
80
+ 'node/no-unsupported-features/es-syntax': 'off', // assume esmod-pmb
81
+ },
82
+ },
83
+ { files: devDepPatternsList,
84
+ rules: {
85
+ 'node/no-unpublished-import': 'off',
86
+ },
87
+ },
88
+ ];
89
+
90
+
76
91
  const config = {
77
92
 
78
93
  env: {
@@ -87,14 +102,7 @@ const config = {
87
102
  'plugin:node/recommended',
88
103
  ],
89
104
 
90
- overrides: [
91
- { files: ['**.js'], parserOptions: { sourceType: 'script' } },
92
- { files: devDepPatternsList,
93
- rules: {
94
- 'node/no-unpublished-import': 'off',
95
- },
96
- },
97
- ],
105
+ overrides,
98
106
 
99
107
  parser: require.resolve('@babel/eslint-parser'),
100
108
  parserOptions: {
@@ -3,7 +3,7 @@
3
3
 
4
4
  module.exports = (function depsHelper(require) {
5
5
  return [
6
- require('eslint-plugin-json-light'),
6
+ require('eslint-plugin-json-light-pmb'),
7
7
  require('eslint-plugin-node'),
8
8
  ];
9
9
  }(String));
@@ -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