Skip to content

Commit b62fc8c

Browse files
authored
chore: eslint rule for naming convention (#9208)
1 parent 8667f0f commit b62fc8c

File tree

99 files changed

+585
-551
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

99 files changed

+585
-551
lines changed

packages/svelte/package.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,7 @@
8383
"posttest": "agadoo src/internal/index.js",
8484
"prepublishOnly": "pnpm build",
8585
"types": "node ./scripts/generate-dts.js",
86-
"lint": "prettier . --cache --plugin-search-dir=. --check && eslint \"{src,test}/**/*.{ts,js}\" --cache"
86+
"lint": "prettier . --cache --plugin-search-dir=. --check && eslint \"{scripts,src,test}/**/*.js\" --cache --fix"
8787
},
8888
"repository": {
8989
"type": "git",
@@ -129,6 +129,7 @@
129129
"agadoo": "^3.0.0",
130130
"dts-buddy": "^0.1.7",
131131
"esbuild": "^0.18.11",
132+
"eslint-plugin-lube": "^0.1.7",
132133
"happy-dom": "^9.20.3",
133134
"jsdom": "^21.1.2",
134135
"kleur": "^4.1.5",
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
{
2+
"plugins": ["lube"],
3+
"rules": {
4+
"lube/svelte-naming-convention": ["error", { "fixSameNames": true }]
5+
}
6+
}

packages/svelte/scripts/compile-test.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
// Compile all Svelte files in a directory to JS and CSS files
22
// Usage: node scripts/compile-test.js <directory>
33

4-
import { mkdirSync, readFileSync, writeFileSync } from 'fs';
5-
import path from 'path';
4+
import { mkdirSync, readFileSync, writeFileSync } from 'node:fs';
5+
import path from 'node:path';
66
import glob from 'tiny-glob/sync.js';
77
import { compile } from '../src/compiler/index.js';
88

packages/svelte/scripts/generate-dts.js

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,18 @@
1-
import * as fs from 'fs';
1+
import * as fs from 'node:fs';
22
import { createBundle } from 'dts-buddy';
33

44
// It may look weird, but the imports MUST be ending with index.js to be properly resolved in all TS modes
55
for (const name of ['action', 'animate', 'easing', 'motion', 'store', 'transition']) {
6-
fs.writeFileSync(`${name}.d.ts`, `import './types/index.js';`);
6+
fs.writeFileSync(`${name}.d.ts`, "import './types/index.js';");
77
}
88

9-
fs.writeFileSync('index.d.ts', `import './types/index.js';`);
10-
fs.writeFileSync('compiler.d.ts', `import './types/index.js';`);
9+
fs.writeFileSync('index.d.ts', "import './types/index.js';");
10+
fs.writeFileSync('compiler.d.ts', "import './types/index.js';");
1111

1212
// TODO: some way to mark these as deprecated
1313
fs.mkdirSync('./types/compiler', { recursive: true });
14-
fs.writeFileSync('./types/compiler/preprocess.d.ts', `import '../index.js';`);
15-
fs.writeFileSync('./types/compiler/interfaces.d.ts', `import '../index.js';`);
14+
fs.writeFileSync('./types/compiler/preprocess.d.ts', "import '../index.js';");
15+
fs.writeFileSync('./types/compiler/interfaces.d.ts', "import '../index.js';");
1616

1717
await createBundle({
1818
output: 'types/index.d.ts',

packages/svelte/scripts/globals-extractor.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,8 @@ Please run `node scripts/globals-extractor.js` at the project root.
66
see: https://github.com/microsoft/TypeScript/tree/main/lib
77
---------------------------------------------------------------------- */
88

9-
import http from 'https';
10-
import fs from 'fs';
9+
import http from 'node:https';
10+
import fs from 'node:fs';
1111

1212
const GLOBAL_TS_PATH = './src/compiler/utils/globals.js';
1313

packages/svelte/src/.eslintrc.json

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
{
2+
"plugins": ["lube"],
3+
"rules": {
4+
"lube/svelte-naming-convention": ["error", { "fixSameNames": true }]
5+
}
6+
}

packages/svelte/src/compiler/compile/Component.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1555,8 +1555,8 @@ export default class Component {
15551555
}, [])
15561556
);
15571557
if (cycle && cycle.length) {
1558-
const declarationList = lookup.get(cycle[0]);
1559-
const declaration = declarationList[0];
1558+
const declaration_list = lookup.get(cycle[0]);
1559+
const declaration = declaration_list[0];
15601560
return this.error(declaration.node, compiler_errors.cyclical_reactive_declaration(cycle));
15611561
}
15621562

packages/svelte/src/compiler/compile/create_module.js

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import { b } from 'code-red';
44
* @param {any} program
55
* @param {import('estree').Identifier} name
66
* @param {string} banner
7-
* @param {any} sveltePath
7+
* @param {any} svelte_path
88
* @param {Array<{ name: string; alias: import('estree').Identifier }>} helpers
99
* @param {Array<{ name: string; alias: import('estree').Identifier }>} globals
1010
* @param {import('estree').ImportDeclaration[]} imports
@@ -15,21 +15,21 @@ export default function create_module(
1515
program,
1616
name,
1717
banner,
18-
sveltePath = 'svelte',
18+
svelte_path = 'svelte',
1919
helpers,
2020
globals,
2121
imports,
2222
module_exports,
2323
exports_from
2424
) {
25-
const internal_path = `${sveltePath}/internal`;
25+
const internal_path = `${svelte_path}/internal`;
2626
helpers.sort((a, b) => (a.name < b.name ? -1 : 1));
2727
globals.sort((a, b) => (a.name < b.name ? -1 : 1));
2828
return esm(
2929
program,
3030
name,
3131
banner,
32-
sveltePath,
32+
svelte_path,
3333
internal_path,
3434
helpers,
3535
globals,
@@ -41,11 +41,11 @@ export default function create_module(
4141

4242
/**
4343
* @param {any} source
44-
* @param {any} sveltePath
44+
* @param {any} svelte_path
4545
*/
46-
function edit_source(source, sveltePath) {
46+
function edit_source(source, svelte_path) {
4747
return source === 'svelte' || source.startsWith('svelte/')
48-
? source.replace('svelte', sveltePath)
48+
? source.replace('svelte', svelte_path)
4949
: source;
5050
}
5151

@@ -84,7 +84,7 @@ function get_internal_globals(globals, helpers) {
8484
* @param {any} program
8585
* @param {import('estree').Identifier} name
8686
* @param {string} banner
87-
* @param {string} sveltePath
87+
* @param {string} svelte_path
8888
* @param {string} internal_path
8989
* @param {Array<{ name: string; alias: import('estree').Identifier }>} helpers
9090
* @param {Array<{ name: string; alias: import('estree').Identifier }>} globals
@@ -96,7 +96,7 @@ function esm(
9696
program,
9797
name,
9898
banner,
99-
sveltePath,
99+
svelte_path,
100100
internal_path,
101101
helpers,
102102
globals,
@@ -118,7 +118,7 @@ function esm(
118118

119119
/** @param {any} node */
120120
function rewrite_import(node) {
121-
const value = edit_source(node.source.value, sveltePath);
121+
const value = edit_source(node.source.value, svelte_path);
122122
if (node.source.value !== value) {
123123
node.source.value = value;
124124
node.source.raw = null;

packages/svelte/src/compiler/compile/nodes/Binding.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -98,7 +98,7 @@ export default class Binding extends Node {
9898
this.is_readonly =
9999
regex_dimensions.test(this.name) ||
100100
regex_box_size.test(this.name) ||
101-
(isElement(parent) &&
101+
(is_element(parent) &&
102102
((parent.is_media_node() && read_only_media_attributes.has(this.name)) ||
103103
(parent.name === 'input' && type === 'file'))) /* TODO others? */;
104104
}
@@ -127,6 +127,6 @@ export default class Binding extends Node {
127127
* @param {import('./shared/Node.js').default} node
128128
* @returns {node is import('./Element.js').default}
129129
*/
130-
function isElement(node) {
130+
function is_element(node) {
131131
return !!(/** @type {any} */ (node).is_media_node);
132132
}

packages/svelte/src/compiler/compile/nodes/EachBlock.js

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,9 @@ export default class EachBlock extends AbstractBlock {
8484
this.has_animation = false;
8585
[this.const_tags, this.children] = get_const_tags(info.children, component, this, this);
8686
if (this.has_animation) {
87-
this.children = this.children.filter((child) => !isEmptyNode(child) && !isCommentNode(child));
87+
this.children = this.children.filter(
88+
(child) => !is_empty_node(child) && !is_comment_node(child)
89+
);
8890
if (this.children.length !== 1) {
8991
const child = this.children.find(
9092
(child) => !!(/** @type {import('./Element.js').default} */ (child).animation)
@@ -102,11 +104,11 @@ export default class EachBlock extends AbstractBlock {
102104
}
103105

104106
/** @param {import('./interfaces.js').INode} node */
105-
function isEmptyNode(node) {
107+
function is_empty_node(node) {
106108
return node.type === 'Text' && node.data.trim() === '';
107109
}
108110

109111
/** @param {import('./interfaces.js').INode} node */
110-
function isCommentNode(node) {
112+
function is_comment_node(node) {
111113
return node.type === 'Comment';
112114
}

packages/svelte/src/compiler/compile/nodes/Element.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -875,7 +875,7 @@ export default class Element extends Node {
875875
) {
876876
const interactive_handlers = handlers
877877
.map((handler) => handler.name)
878-
.filter((handlerName) => a11y_interactive_handlers.has(handlerName));
878+
.filter((handler_name) => a11y_interactive_handlers.has(handler_name));
879879
if (interactive_handlers.length > 0) {
880880
component.warn(
881881
this,

packages/svelte/src/compiler/compile/nodes/shared/get_const_tags.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -73,8 +73,8 @@ function sort_consts_nodes(consts_nodes, component) {
7373
}, [])
7474
);
7575
if (cycle && cycle.length) {
76-
const nodeList = lookup.get(cycle[0]);
77-
const node = nodeList[0];
76+
const node_list = lookup.get(cycle[0]);
77+
const node = node_list[0];
7878
component.error(node.node, compiler_errors.cyclical_const_tags(cycle));
7979
}
8080

packages/svelte/src/compiler/compile/render_dom/wrappers/Window.js

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -94,14 +94,14 @@ export default class WindowWrapper extends Wrapper {
9494
bindings.scrollX && bindings.scrollY
9595
? x`"${bindings.scrollX}" in this._state || "${bindings.scrollY}" in this._state`
9696
: x`"${bindings.scrollX || bindings.scrollY}" in this._state`;
97-
const scrollX = bindings.scrollX && x`this._state.${bindings.scrollX}`;
98-
const scrollY = bindings.scrollY && x`this._state.${bindings.scrollY}`;
97+
const scroll_x = bindings.scrollX && x`this._state.${bindings.scrollX}`;
98+
const scroll_y = bindings.scrollY && x`this._state.${bindings.scrollY}`;
9999
renderer.meta_bindings.push(b`
100100
if (${condition}) {
101-
@_scrollTo(${scrollX || '@_window.pageXOffset'}, ${scrollY || '@_window.pageYOffset'});
101+
@_scrollTo(${scroll_x || '@_window.pageXOffset'}, ${scroll_y || '@_window.pageYOffset'});
102102
}
103-
${scrollX && `${scrollX} = @_window.pageXOffset;`}
104-
${scrollY && `${scrollY} = @_window.pageYOffset;`}
103+
${scroll_x && `${scroll_x} = @_window.pageXOffset;`}
104+
${scroll_y && `${scroll_y} = @_window.pageYOffset;`}
105105
`);
106106
block.event_listeners.push(x`
107107
@listen(@_window, "${event}", () => {
@@ -132,17 +132,17 @@ export default class WindowWrapper extends Wrapper {
132132
// special case... might need to abstract this out if we add more special cases
133133
if (bindings.scrollX || bindings.scrollY) {
134134
const condition = renderer.dirty([bindings.scrollX, bindings.scrollY].filter(Boolean));
135-
const scrollX = bindings.scrollX
135+
const scroll_x = bindings.scrollX
136136
? renderer.reference(bindings.scrollX)
137137
: x`@_window.pageXOffset`;
138-
const scrollY = bindings.scrollY
138+
const scroll_y = bindings.scrollY
139139
? renderer.reference(bindings.scrollY)
140140
: x`@_window.pageYOffset`;
141141
block.chunks.update.push(b`
142142
if (${condition} && !${scrolling}) {
143143
${scrolling} = true;
144144
@_clearTimeout(${scrolling_timeout});
145-
@_scrollTo(${scrollX}, ${scrollY});
145+
@_scrollTo(${scroll_x}, ${scroll_y});
146146
${scrolling_timeout} = @_setTimeout(${clear_scrolling}, 100);
147147
}
148148
`);

packages/svelte/src/compiler/parse/read/css-tree-cq/css_tree_parse.js

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,21 +8,21 @@ import * as node from './node/index.js';
88
*
99
* The new nodes are located in `./node`.
1010
*/
11-
const cqSyntax = fork({
11+
const cq_syntax = fork({
1212
atrule: {
1313
// extend or override at-rule dictionary
1414
container: {
1515
parse: {
1616
prelude() {
1717
return this.createSingleNodeList(this.ContainerQuery());
1818
},
19-
block(isStyleBlock = false) {
20-
return this.Block(isStyleBlock);
19+
block(is_style_block = false) {
20+
return this.Block(is_style_block);
2121
}
2222
}
2323
}
2424
},
2525
node
2626
});
2727

28-
export const parse = cqSyntax.parse;
28+
export const parse = cq_syntax.parse;

packages/svelte/src/compiler/parse/read/css-tree-cq/node/query_feature_range.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ export const structure = {
1616
value: ['Identifier', 'Number', 'Comparison', 'Dimension', 'QueryCSSFunction', 'Ratio', null]
1717
};
1818

19-
function lookup_non_WS_type_and_value(offset, type, referenceStr) {
19+
function lookup_non_ws_type_and_value(offset, type, reference_str) {
2020
let current_type;
2121

2222
do {
@@ -26,7 +26,7 @@ function lookup_non_WS_type_and_value(offset, type, referenceStr) {
2626
}
2727
} while (current_type !== 0); // NULL -> 0
2828

29-
return current_type === type ? this.lookupValue(offset - 1, referenceStr) : false;
29+
return current_type === type ? this.lookupValue(offset - 1, reference_str) : false;
3030
}
3131

3232
export function parse() {
@@ -40,7 +40,7 @@ export function parse() {
4040
while (!this.eof && this.tokenType !== RightParenthesis) {
4141
switch (this.tokenType) {
4242
case Number:
43-
if (lookup_non_WS_type_and_value.call(this, 1, Delim, '/')) {
43+
if (lookup_non_ws_type_and_value.call(this, 1, Delim, '/')) {
4444
child = this.Ratio();
4545
} else {
4646
child = this.Number();

0 commit comments

Comments
 (0)