eslint-plugin-lube 0.5.0 → 0.6.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/CHANGELOG.md +260 -0
- package/LICENSE +21 -0
- package/README.md +120 -9
- package/docs/ascii-order.md +81 -0
- package/docs/pretty-imports.md +70 -59
- package/docs/pretty-jsdoc-casting.md +31 -23
- package/docs/pretty-sequence.md +129 -117
- package/docs/pretty-ternary.md +55 -0
- package/docs/svelte-naming-convention.md +59 -46
- package/package.json +60 -36
- package/src/index.js +299 -0
- package/src/rules/ascii-order.js +940 -0
- package/src/rules/pretty-imports.js +176 -0
- package/src/rules/pretty-jsdoc-casting.js +278 -0
- package/src/rules/pretty-sequence.js +489 -0
- package/src/rules/pretty-ternary.js +227 -0
- package/src/rules/svelte-naming-convention.js +903 -0
- package/src/utils/fix_recorder.js +50 -0
- package/src/utils/keep_comments.js +99 -0
- package/src/utils/keep_line_breaks.js +56 -0
- package/src/utils/skip_hole_commas.js +32 -0
- package/src/utils/skip_optional_patterns.js +27 -0
- package/src/utils/skip_unchanged_fixes.js +35 -0
- package/src/utils/source_text.js +442 -0
- package/src/utils/split_declarations.js +75 -0
- package/src/utils/text_width.js +9 -0
- package/types/index.d.ts +29 -0
- package/types/index.d.ts.map +1 -0
- package/index.js +0 -125
- package/private.d.ts +0 -168
- package/rules/pretty-imports.js +0 -147
- package/rules/pretty-jsdoc-casting.js +0 -236
- package/rules/pretty-sequence.js +0 -441
- package/rules/svelte-naming-convention.js +0 -361
- package/test/pretty-imports/ExportNamedDeclaration.js +0 -123
- package/test/pretty-imports/ImportDeclaration.js +0 -125
- package/test/pretty-imports.js +0 -20
- package/test/pretty-jsdoc-casting/case_by_expression.js +0 -249
- package/test/pretty-jsdoc-casting/various_situations.js +0 -95
- package/test/pretty-jsdoc-casting.js +0 -22
- package/test/pretty-sequence/case_by_node_type.js +0 -340
- package/test/pretty-sequence/case_by_option.js +0 -142
- package/test/pretty-sequence/various_situations.js +0 -193
- package/test/pretty-sequence.js +0 -23
- package/test/svelte-naming-convention/basic_snake_case.js +0 -54
- package/test/svelte-naming-convention/case_by_identifier.js +0 -878
- package/test/svelte-naming-convention/snake_case_with_symbols.js +0 -46
- package/test/svelte-naming-convention.js +0 -25
- package/tsconfig.json +0 -16
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @param {import("eslint").AST.Range} range
|
|
3
|
+
* @param {string} text
|
|
4
|
+
* @returns {import("eslint").Rule.Fix}
|
|
5
|
+
*/
|
|
6
|
+
function fix_of(range, text) {
|
|
7
|
+
return { range, text }
|
|
8
|
+
}
|
|
9
|
+
/** @type {import("eslint").Rule.RuleFixer} */
|
|
10
|
+
const recorder = {
|
|
11
|
+
insertTextAfter: (node, text) => fix_of(
|
|
12
|
+
[
|
|
13
|
+
/** @type {import("eslint").AST.Range} */(node.range)/**/[1],
|
|
14
|
+
/** @type {import("eslint").AST.Range} */(node.range)/**/[1]
|
|
15
|
+
],
|
|
16
|
+
text
|
|
17
|
+
),
|
|
18
|
+
insertTextAfterRange: (range, text) => fix_of([ range[1], range[1] ], text),
|
|
19
|
+
insertTextBefore: (node, text) => fix_of(
|
|
20
|
+
[
|
|
21
|
+
/** @type {import("eslint").AST.Range} */(node.range)/**/[0],
|
|
22
|
+
/** @type {import("eslint").AST.Range} */(node.range)/**/[0]
|
|
23
|
+
],
|
|
24
|
+
text
|
|
25
|
+
),
|
|
26
|
+
insertTextBeforeRange: (range, text) => fix_of([ range[0], range[0] ], text),
|
|
27
|
+
remove: node => fix_of(
|
|
28
|
+
/** @type {import("eslint").AST.Range} */(node.range)/**/,
|
|
29
|
+
""
|
|
30
|
+
),
|
|
31
|
+
removeRange: range => fix_of(range, ""),
|
|
32
|
+
replaceText: (node, text) => fix_of(
|
|
33
|
+
/** @type {import("eslint").AST.Range} */(node.range)/**/,
|
|
34
|
+
text
|
|
35
|
+
),
|
|
36
|
+
replaceTextRange: (range, text) => fix_of(range, text)
|
|
37
|
+
}
|
|
38
|
+
/**
|
|
39
|
+
* @param {import("eslint").Rule.ReportDescriptor} descriptor
|
|
40
|
+
* @returns {import("eslint").Rule.Fix[]}
|
|
41
|
+
*/
|
|
42
|
+
function get_fixes(descriptor) {
|
|
43
|
+
const fix = descriptor.fix?.(recorder)
|
|
44
|
+
return fix == null
|
|
45
|
+
? []
|
|
46
|
+
: "range" in fix
|
|
47
|
+
? [ fix ]
|
|
48
|
+
: [ ...fix ]
|
|
49
|
+
}
|
|
50
|
+
export { get_fixes }
|
|
@@ -0,0 +1,99 @@
|
|
|
1
|
+
import { get_fixes } from "./fix_recorder.js"
|
|
2
|
+
import { lower_bound } from "./source_text.js"
|
|
3
|
+
const line_break_regex = /^[\n\r\p{Zl}\p{Zp}]/u
|
|
4
|
+
const non_space_regex = /\S/
|
|
5
|
+
/**
|
|
6
|
+
* @param {import("../../private.js").Comment} comment
|
|
7
|
+
* @returns {number}
|
|
8
|
+
*/
|
|
9
|
+
function get_comment_start(comment) {
|
|
10
|
+
return comment.range[0]
|
|
11
|
+
}
|
|
12
|
+
/**
|
|
13
|
+
* @param {import("eslint").Rule.RuleModule} rule
|
|
14
|
+
* @returns {import("eslint").Rule.RuleModule}
|
|
15
|
+
*/
|
|
16
|
+
function keep_comment_order(rule) {
|
|
17
|
+
return {
|
|
18
|
+
...rule,
|
|
19
|
+
create(context) {
|
|
20
|
+
const source_code = context.sourceCode
|
|
21
|
+
const comments = /** @type {import("../../private.js").Comment[]} */(source_code.getAllComments())/**/
|
|
22
|
+
return rule.create(
|
|
23
|
+
Object.create(
|
|
24
|
+
context,
|
|
25
|
+
{
|
|
26
|
+
report: {
|
|
27
|
+
value: (
|
|
28
|
+
/** @type {import("eslint").Rule.ReportDescriptor} */ descriptor
|
|
29
|
+
) => {
|
|
30
|
+
const fixes = get_fixes(descriptor)
|
|
31
|
+
if (fixes.some(
|
|
32
|
+
item => {
|
|
33
|
+
const comment = comments[lower_bound(
|
|
34
|
+
comments,
|
|
35
|
+
get_comment_start,
|
|
36
|
+
item.range[0]
|
|
37
|
+
)]
|
|
38
|
+
return !!comment && comment.range[1] <= item.range[1]
|
|
39
|
+
}
|
|
40
|
+
)) return
|
|
41
|
+
context.report(descriptor)
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
)
|
|
46
|
+
)
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
/**
|
|
51
|
+
* @param {import("eslint").Rule.RuleModule} rule
|
|
52
|
+
* @returns {import("eslint").Rule.RuleModule}
|
|
53
|
+
*/
|
|
54
|
+
function keep_comments(rule) {
|
|
55
|
+
return {
|
|
56
|
+
...rule,
|
|
57
|
+
create(context) {
|
|
58
|
+
const source_code = context.sourceCode
|
|
59
|
+
const text = source_code.text
|
|
60
|
+
/** @type {Set<number> | undefined} */
|
|
61
|
+
let line_comment_ends
|
|
62
|
+
return rule.create(
|
|
63
|
+
Object.create(
|
|
64
|
+
context,
|
|
65
|
+
{
|
|
66
|
+
report: {
|
|
67
|
+
value: (
|
|
68
|
+
/** @type {import("eslint").Rule.ReportDescriptor} */ descriptor
|
|
69
|
+
) => {
|
|
70
|
+
const fixes = get_fixes(descriptor)
|
|
71
|
+
line_comment_ends ??= new Set(
|
|
72
|
+
source_code.getAllComments()
|
|
73
|
+
.filter(
|
|
74
|
+
comment => comment.type == "Line"
|
|
75
|
+
)
|
|
76
|
+
.map(
|
|
77
|
+
comment => /** @type {import("eslint").AST.Range} */(comment.range)/**/[1]
|
|
78
|
+
)
|
|
79
|
+
)
|
|
80
|
+
const ends = line_comment_ends
|
|
81
|
+
if (fixes.some(
|
|
82
|
+
item => non_space_regex.test(
|
|
83
|
+
text.slice(item.range[0], item.range[1])
|
|
84
|
+
)
|
|
85
|
+
|| ends.has(item.range[0]) && !line_break_regex.test(item.text)
|
|
86
|
+
)) return
|
|
87
|
+
context.report(descriptor)
|
|
88
|
+
}
|
|
89
|
+
}
|
|
90
|
+
}
|
|
91
|
+
)
|
|
92
|
+
)
|
|
93
|
+
}
|
|
94
|
+
}
|
|
95
|
+
}
|
|
96
|
+
export {
|
|
97
|
+
keep_comment_order,
|
|
98
|
+
keep_comments
|
|
99
|
+
}
|
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
import { create_source_text } from "./source_text.js"
|
|
2
|
+
const lf_regex = /(?<!\r)\n/g
|
|
3
|
+
/**
|
|
4
|
+
* @param {import("eslint").Rule.RuleModule} rule
|
|
5
|
+
* @returns {import("eslint").Rule.RuleModule}
|
|
6
|
+
*/
|
|
7
|
+
function keep_line_breaks(rule) {
|
|
8
|
+
return {
|
|
9
|
+
...rule,
|
|
10
|
+
create(context) {
|
|
11
|
+
const eol = create_source_text(context.sourceCode).eol
|
|
12
|
+
if (eol == "\n") return rule.create(context)
|
|
13
|
+
return rule.create(
|
|
14
|
+
Object.create(
|
|
15
|
+
context,
|
|
16
|
+
{
|
|
17
|
+
report: {
|
|
18
|
+
value: (
|
|
19
|
+
/** @type {import("eslint").Rule.ReportDescriptor} */ descriptor
|
|
20
|
+
) => {
|
|
21
|
+
const fix = descriptor.fix
|
|
22
|
+
context.report(
|
|
23
|
+
fix
|
|
24
|
+
? {
|
|
25
|
+
...descriptor,
|
|
26
|
+
fix(fixer) {
|
|
27
|
+
const result = fix(fixer)
|
|
28
|
+
return result == null
|
|
29
|
+
? result
|
|
30
|
+
: "range" in result
|
|
31
|
+
? to_eol(result, eol)
|
|
32
|
+
: [ ...result ].map(item => to_eol(item, eol))
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
: descriptor
|
|
36
|
+
)
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
)
|
|
41
|
+
)
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
/**
|
|
46
|
+
* @param {import("eslint").Rule.Fix} fix
|
|
47
|
+
* @param {string} eol
|
|
48
|
+
* @returns {import("eslint").Rule.Fix}
|
|
49
|
+
*/
|
|
50
|
+
function to_eol(fix, eol) {
|
|
51
|
+
return {
|
|
52
|
+
range: fix.range,
|
|
53
|
+
text: fix.text.replace(lf_regex, eol)
|
|
54
|
+
}
|
|
55
|
+
}
|
|
56
|
+
export { keep_line_breaks }
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @param {import("eslint").Rule.RuleModule} rule
|
|
3
|
+
* @returns {import("eslint").Rule.RuleModule}
|
|
4
|
+
*/
|
|
5
|
+
function skip_hole_commas(rule) {
|
|
6
|
+
return {
|
|
7
|
+
...rule,
|
|
8
|
+
create(context) {
|
|
9
|
+
const source_code = context.sourceCode
|
|
10
|
+
return rule.create(
|
|
11
|
+
Object.create(
|
|
12
|
+
context,
|
|
13
|
+
{
|
|
14
|
+
report: {
|
|
15
|
+
value: (
|
|
16
|
+
/** @type {import("eslint").Rule.ReportDescriptor & { node?: import("eslint").AST.Token }} */ descriptor
|
|
17
|
+
) => {
|
|
18
|
+
const token = descriptor.node
|
|
19
|
+
if (token?.type == "Punctuator" && token.value == ",") {
|
|
20
|
+
const before = source_code.getTokenBefore(token)
|
|
21
|
+
if (before?.value == "," && before.loc.end.line < token.loc.start.line) return
|
|
22
|
+
}
|
|
23
|
+
context.report(descriptor)
|
|
24
|
+
}
|
|
25
|
+
}
|
|
26
|
+
}
|
|
27
|
+
)
|
|
28
|
+
)
|
|
29
|
+
}
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
export { skip_hole_commas }
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @param {import("eslint").Rule.RuleModule} rule
|
|
3
|
+
* @returns {import("eslint").Rule.RuleModule}
|
|
4
|
+
*/
|
|
5
|
+
function skip_optional_patterns(rule) {
|
|
6
|
+
return {
|
|
7
|
+
...rule,
|
|
8
|
+
create(context) {
|
|
9
|
+
return rule.create(
|
|
10
|
+
Object.create(
|
|
11
|
+
context,
|
|
12
|
+
{
|
|
13
|
+
report: {
|
|
14
|
+
value: (
|
|
15
|
+
/** @type {import("eslint").Rule.ReportDescriptor & { node?: import("estree").Node & { optional?: boolean } }} */ descriptor
|
|
16
|
+
) => {
|
|
17
|
+
if (descriptor.node?.type == "ObjectPattern" && descriptor.node.optional) return
|
|
18
|
+
context.report(descriptor)
|
|
19
|
+
}
|
|
20
|
+
}
|
|
21
|
+
}
|
|
22
|
+
)
|
|
23
|
+
)
|
|
24
|
+
}
|
|
25
|
+
}
|
|
26
|
+
}
|
|
27
|
+
export { skip_optional_patterns }
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
import { get_fixes } from "./fix_recorder.js"
|
|
2
|
+
/**
|
|
3
|
+
* @param {import("eslint").Rule.RuleModule} rule
|
|
4
|
+
* @returns {import("eslint").Rule.RuleModule}
|
|
5
|
+
*/
|
|
6
|
+
function skip_unchanged_fixes(rule) {
|
|
7
|
+
return {
|
|
8
|
+
...rule,
|
|
9
|
+
create(context) {
|
|
10
|
+
const text = context.sourceCode.text
|
|
11
|
+
return rule.create(
|
|
12
|
+
Object.create(
|
|
13
|
+
context,
|
|
14
|
+
{
|
|
15
|
+
report: {
|
|
16
|
+
value: (
|
|
17
|
+
/** @type {import("eslint").Rule.ReportDescriptor} */ descriptor
|
|
18
|
+
) => {
|
|
19
|
+
const fixes = get_fixes(descriptor)
|
|
20
|
+
if (
|
|
21
|
+
fixes.length
|
|
22
|
+
&& fixes.every(
|
|
23
|
+
item => text.slice(item.range[0], item.range[1]) == item.text
|
|
24
|
+
)
|
|
25
|
+
) return
|
|
26
|
+
context.report(descriptor)
|
|
27
|
+
}
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
)
|
|
31
|
+
)
|
|
32
|
+
}
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
export { skip_unchanged_fixes }
|