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
}

0 commit comments

Comments
 (0)