eslint-plugin-hex-under 1.0.0 → 1.1.0

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/README.md CHANGED
@@ -22,6 +22,13 @@ const binary = 0b1111_1111;
22
22
 
23
23
  const octal = 0o377;
24
24
 
25
+ /* You can also turn off the rule with a comment, see next examples */
26
+ // ignore-hex-under
27
+ const hexTooBig = 0xfffff;
28
+ const binTooBig = 0b1000_0000_0000; // ignore-binary-under
29
+ // ignore-octal-under
30
+ const octalTooBig = 0o777777;
31
+
25
32
  // valid with { limit: 255, skipBigInt: true }
26
33
  const mask = 0xdead_beefn;
27
34
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "eslint-plugin-hex-under",
3
- "version": "1.0.0",
3
+ "version": "1.1.0",
4
4
  "type": "module",
5
5
  "main": "src/eslint-plugin-hex-under.js",
6
6
  "scripts": {
@@ -28,10 +28,23 @@ export default {
28
28
 
29
29
  create(context) {
30
30
  const [{ limit = 15, skipBigInt = false } = {}] = context.options;
31
-
31
+ let comments = [];
32
32
  return {
33
+ Program(node) {
34
+ comments = node.comments || [];
35
+ },
33
36
  'Literal[raw=/^0[bB][01_]+n?$/]'(node) {
34
37
  const raw = node.raw;
38
+
39
+ const ignore = comments.some((c) => {
40
+ const line = c.loc.end.line;
41
+ return (
42
+ (line === node.loc.start.line - 1 || line === node.loc.end.line) &&
43
+ c.value.trim() === 'ignore-binary-under'
44
+ );
45
+ });
46
+ if (ignore) return;
47
+
35
48
  const isBigInt = BINARY_REGEX_BIGINT.test(raw);
36
49
  const isBinary = BINARY_REGEX.test(raw);
37
50
 
@@ -40,10 +40,23 @@ export default {
40
40
 
41
41
  create(context) {
42
42
  const [{ limit = 255, skipBigInt = false } = {}] = context.options;
43
-
43
+ let comments = [];
44
44
  return {
45
+ Program(node) {
46
+ comments = node.comments || [];
47
+ },
45
48
  'Literal[raw=/^0[xX][0-9a-fA-F_]+n?$/]'(node) {
46
49
  const raw = node.raw;
50
+
51
+ const ignore = comments.some((c) => {
52
+ const line = c.loc.end.line;
53
+ return (
54
+ (line === node.loc.start.line - 1 || line === node.loc.end.line) &&
55
+ c.value.trim() === 'ignore-hex-under'
56
+ );
57
+ });
58
+ if (ignore) return;
59
+
47
60
  const isHexBigInt = HEX_REGEX_BIGINT.test(raw);
48
61
  const isHex = HEX_REGEX.test(raw);
49
62
 
@@ -28,11 +28,23 @@ export default {
28
28
 
29
29
  create(context) {
30
30
  const [{ limit = 511, skipBigInt = false } = {}] = context.options;
31
-
31
+ let comments = [];
32
32
  return {
33
+ Program(node) {
34
+ comments = node.comments || [];
35
+ },
33
36
  'Literal[raw=/^0[oO]?[0-7_]+n?$/]'(node) {
34
37
  const raw = node.raw;
35
38
 
39
+ const ignore = comments.some((c) => {
40
+ const line = c.loc.end.line;
41
+ return (
42
+ (line === node.loc.start.line - 1 || line === node.loc.end.line) &&
43
+ c.value.trim() === 'ignore-octal-under'
44
+ );
45
+ });
46
+ if (ignore) return;
47
+
36
48
  if (
37
49
  raw.startsWith('0') &&
38
50
  !raw.startsWith('0o') &&