@dataport/eslint-config-geodev 0.3.2 → 0.3.3

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.
@@ -0,0 +1,21 @@
1
+ import json from '@eslint/json'
2
+ import dataportGeodev from '../rules/index.js'
3
+
4
+ export default [
5
+ {
6
+ plugins: {
7
+ json,
8
+ },
9
+ language: 'json/json',
10
+ ...json.configs.recommended,
11
+ },
12
+ {
13
+ plugins: {
14
+ 'dataport-geodev': dataportGeodev,
15
+ },
16
+ rules: {
17
+ 'json/top-level-interop': 'error',
18
+ 'dataport-geodev/json-indent': 'error',
19
+ },
20
+ },
21
+ ]
@@ -0,0 +1,16 @@
1
+ import markdown from '@eslint/markdown'
2
+
3
+ export default [
4
+ {
5
+ plugins: {
6
+ markdown,
7
+ },
8
+ language: 'json/json',
9
+ },
10
+ ...markdown.configs.recommended,
11
+ {
12
+ rules: {
13
+ 'markdown/no-missing-label-refs': 'off',
14
+ },
15
+ },
16
+ ]
package/configs/node.js CHANGED
@@ -9,6 +9,6 @@ export default [
9
9
  },
10
10
  rules: {
11
11
  'no-console': ['error', { allow: ['warn', 'error', 'info'] }],
12
- }
12
+ },
13
13
  },
14
14
  ]
package/configs/vue.js CHANGED
@@ -12,7 +12,7 @@ export default [
12
12
  js: 'espree',
13
13
  ts: tsParser,
14
14
  },
15
- extraFileExtensions: [ '.vue' ],
15
+ extraFileExtensions: ['.vue'],
16
16
  },
17
17
  },
18
18
  },
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@dataport/eslint-config-geodev",
3
- "version": "0.3.2",
3
+ "version": "0.3.3",
4
4
  "description": "Generic ESLint configuration for geo development projects at Dataport",
5
5
  "type": "module",
6
6
  "main": "configs/index.js",
@@ -9,6 +9,8 @@
9
9
  "./node": "./configs/node.js",
10
10
  "./browser": "./configs/browser.js",
11
11
  "./typescript": "./configs/typescript.js",
12
+ "./json": "./configs/json.js",
13
+ "./markdown": "./configs/markdown.js",
12
14
  "./vue": "./configs/vue.js",
13
15
  "./vue-pug": "./configs/vue-pug.js",
14
16
  "./vue2": "./configs/vue2.js"
@@ -29,6 +31,8 @@
29
31
  "homepage": "https://github.com/Dataport/eslint-config-geodev#readme",
30
32
  "dependencies": {
31
33
  "@eslint/js": "^9.25.1",
34
+ "@eslint/json": "^0.12.0",
35
+ "@eslint/markdown": "^6.6.0",
32
36
  "@typescript-eslint/parser": "^8.34.1",
33
37
  "eslint-plugin-tsdoc": "^0.4.0",
34
38
  "eslint-plugin-vue": "^10.0.0",
package/rules/index.js ADDED
@@ -0,0 +1,7 @@
1
+ import jsonIndent from './json-indent.js'
2
+
3
+ export default {
4
+ rules: {
5
+ 'json-indent': jsonIndent,
6
+ },
7
+ }
@@ -0,0 +1,115 @@
1
+ export default {
2
+ meta: {
3
+ type: 'layout',
4
+ docs: {
5
+ description: 'Require proper indentation with tabs in JSON files.',
6
+ },
7
+ fixable: 'whitespace',
8
+ schema: [],
9
+ messages: {
10
+ mixedSpaces: 'Invalid indentation, expected {{ expected }} tabs but found {{ found }} tabs and {{ foundSpaces }} spaces',
11
+ invalidSpaces: 'Invalid indentation, expected {{ expected }} tabs but found {{ found }} spaces',
12
+ invalidDepth: 'Invalid indentation, expected {{ expected }} tabs but found {{ found }} tabs',
13
+ inLine: 'Indentation started within a line?',
14
+ },
15
+ },
16
+
17
+ create (context) {
18
+ const text = context.sourceCode.getText()
19
+ let level = 0
20
+ let checkedLine = -1
21
+
22
+ function checkIndentLevel (pos, expected, node) {
23
+ let found = 0
24
+ let foundSpaces = 0
25
+ let x = pos - 1
26
+ for (;; x--) {
27
+ if (x < 0) break
28
+ if (text[x] === '\t') {
29
+ found++
30
+ } else if (text[x] === ' ') {
31
+ foundSpaces++
32
+ } else break
33
+ }
34
+ if (x > -1 && text[x] !== '\n') {
35
+ context.report({
36
+ loc: node.loc,
37
+ messageId: 'inLine',
38
+ })
39
+ return
40
+ }
41
+ function fix (fixer) {
42
+ return fixer.replaceTextRange([x + 1, pos], '\t'.repeat(expected))
43
+ }
44
+ if (foundSpaces > 0 && found > 0) {
45
+ context.report({
46
+ loc: node.loc,
47
+ messageId: 'mixedSpaces',
48
+ data: {
49
+ expected,
50
+ found,
51
+ foundSpaces,
52
+ },
53
+ fix,
54
+ })
55
+ } else if (foundSpaces > 0) {
56
+ context.report({
57
+ loc: node.loc,
58
+ messageId: 'invalidSpaces',
59
+ data: {
60
+ expected,
61
+ found: foundSpaces,
62
+ },
63
+ fix,
64
+ })
65
+ } else if (expected !== found) {
66
+ context.report({
67
+ loc: node.loc,
68
+ messageId: 'invalidDepth',
69
+ data: {
70
+ expected,
71
+ found,
72
+ },
73
+ fix,
74
+ })
75
+ }
76
+ }
77
+
78
+ return {
79
+ Object (node) {
80
+ level++
81
+ checkedLine = node.loc.start.line
82
+ },
83
+ 'Object:exit' (node) {
84
+ level--
85
+ },
86
+ Member (node) {
87
+ if (checkedLine === node.loc.start.line) return
88
+ checkIndentLevel(node.range[0], level, node)
89
+ checkedLine = node.loc.start.line
90
+ },
91
+ 'Member:exit' (node) {
92
+ if (checkedLine === node.loc.end.line) return
93
+ checkIndentLevel(node.range[1] - 1, level, node)
94
+ checkedLine = node.loc.end.line
95
+ },
96
+ Array (node) {
97
+ level++
98
+ checkedLine = node.loc.start.line
99
+ },
100
+ 'Array:exit' (node) {
101
+ level--
102
+ },
103
+ Element (node) {
104
+ if (checkedLine === node.loc.start.line) return
105
+ checkIndentLevel(node.value.range[0], level, node)
106
+ checkedLine = node.loc.start.line
107
+ },
108
+ 'Element:exit' (node) {
109
+ if (checkedLine === node.loc.end.line) return
110
+ checkIndentLevel(node.value.range[1] - 1, level, node)
111
+ checkedLine = node.loc.end.line
112
+ },
113
+ }
114
+ },
115
+ }