Skip to content

Commit

Permalink
Merge pull request #179 from vatro/fix-eslint-rest
Browse files Browse the repository at this point in the history
Fix remaining ESLint warnings, leave those with issues.
See #170 for more details.

Current Status:
svelte-check: no errors / warnings / hints
lint: 0 errors, 3 warnings

The remaining 3 warnings should be fixed by: #135, #175 and #176
  • Loading branch information
vatro authored Oct 4, 2022
2 parents 8af2649 + b009162 commit cb2120f
Show file tree
Hide file tree
Showing 67 changed files with 2,147 additions and 1,558 deletions.
3 changes: 3 additions & 0 deletions .eslintignore
Original file line number Diff line number Diff line change
Expand Up @@ -17,3 +17,6 @@ yarn.lock
/src/lib/components-check
/src/lib/components-internal-check
generate_svelthree_components.js

# Ignore Error tests
/src/routes/error_tests
15 changes: 11 additions & 4 deletions .eslintrc.cjs
Original file line number Diff line number Diff line change
Expand Up @@ -7,24 +7,31 @@ module.exports = {
plugins: ["svelte3", "@typescript-eslint"],

//(default) check *.svelte and *.ts files
// ignorePatterns: ["*.cjs"],
ignorePatterns: ["*.cjs"],

// check only *.svelte files
ignorePatterns: ["*.cjs", "*.ts"],
//ignorePatterns: ["*.cjs", "*.ts"],

overrides: [
{
files: ["*.svelte"],
processor: "svelte3/svelte3",
processor: "svelte3/svelte3"

// checking specific rules (set to "off" / "error")
// errors only
rules: {
/* rules: {
"no-inferrable-types": "error",
"no-undef": "error",
"no-empty": "error",
"no-case-declarations": "error",
"no-prototype-builtins": "error"
} */
},
// see: https://typescript-eslint.io/docs/linting/troubleshooting/#i-get-errors-from-the-no-undef-rule-about-global-variables-not-being-defined-even-though-there-are-no-typescript-errors
{
files: ["*.ts", "*.mts", "*.cts", "*.tsx", "*.svelte"],
rules: {
"no-undef": "off"
}
}
],
Expand Down
8 changes: 7 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -11,4 +11,10 @@ node_modules
/generator
/src/lib/components-check
/src/lib/components-internal-check
generate_svelthree_components.js
generate_svelthree_components.js

# any routes
src/routes/

# app.html
src/app.html
15 changes: 14 additions & 1 deletion .prettierrc
Original file line number Diff line number Diff line change
Expand Up @@ -8,5 +8,18 @@
"endOfLine": "crlf",
"pluginSearchDirs": ["."],
"bracketSameLine": false,
"overrides": [{ "files": "*.svelte", "options": { "parser": "svelte" } }]
"overrides": [
{
"files": "*.svelte",
"options": {
"parser": "svelte"
}
},
{
"files": "src/lib/types/*.ts",
"options": {
"printWidth": 160
}
}
]
}
28 changes: 18 additions & 10 deletions postprocess_package.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,12 +14,14 @@ const replace_tasks = [
//regex: /get mat\(\).*}>>;/s,
//regex: /get mat\(\).*?};/s,
regex: /get mat\(\).*?>;/s, //opt2
replacement: `get mat(): MeshProps<AssignedMaterial>['mat'];`
//replacement: `get mat(): MeshProps<AssignedMaterial>['mat'];`
replacement: `get mat(): PropMat<AssignedMaterial>;`
},
{
//regex: /set mat\(.*}>>\);/s,
regex: /set mat\(.*?\);/s, // opt2
replacement: `set mat(_: MeshProps<AssignedMaterial>['mat']);`
//replacement: `set mat(_: MeshProps<AssignedMaterial>['mat']);`
replacement: `set mat(_: PropMat<AssignedMaterial>);`
}
]
},
Expand All @@ -30,12 +32,14 @@ const replace_tasks = [
//regex: /get mat\(\).*}>>;/s,
//regex: /get mat\(\).*?};/s,
regex: /get mat\(\).*?>;/s, //opt2
replacement: `get mat(): PointsProps<AssignedMaterial>['mat'];`
//replacement: `get mat(): PointsProps<AssignedMaterial>['mat'];`
replacement: `get mat(): PropMat<AssignedMaterial>;`
},
{
//regex: /set mat\(.*}>>\);/s,
regex: /set mat\(.*?\);/s, // opt2
replacement: `set mat(_: PointsProps<AssignedMaterial>['mat']);`
//replacement: `set mat(_: PointsProps<AssignedMaterial>['mat']);`
replacement: `set mat(_: PropMat<AssignedMaterial>);`
}
]
}
Expand Down Expand Up @@ -164,15 +168,15 @@ const get_process_comments_fn = (file_path) => {

for (let [prop_name, comment] of comments_map) {
const str_setter = `set ${prop_name}`
const regex_setter = new RegExp("\\b" + str_setter + "\\b")
const regex_setter = new RegExp(str_setter)
const test_setter = content.match(regex_setter)
const acc_comment = comment.replace(
`/**`,
`/**\n\t * ◁▶ _svelthree-component accessor_ \n\t * \n\t *`
)

if (test_setter) {
new_content = new_content.replace(`set ${prop_name}`, `${acc_comment}\n\tset ${prop_name}`)
new_content = new_content.replace(`set ${prop_name}(_`, `${acc_comment}\n\tset ${prop_name}(_`)
} else {
const str_getter = `get ${prop_name}`
const regex_getter = new RegExp("\\b" + str_getter + "\\b")
Expand Down Expand Up @@ -201,6 +205,8 @@ const get_process_comments_fn = (file_path) => {

// --- ENTRY POINT ---

const schedule_code_replacement_tasks = true

/**
* - Fix generic `mat` shorthand property type when using accessors:
* - Replace `mat` accessors type definitions (accessor getter and setter) -> only `Mesh` and `Points`,
Expand All @@ -217,10 +223,12 @@ const do_postprocess = async () => {
console.log("🤖 SVELTHREE > post-processing package: started...")

// schedule code replacement tasks
console.log("🤖 SVELTHREE > post-processing package: scheduling replacement tasks...")
for (let i = 0; i < replace_tasks.length; i++) {
const task = replace_tasks[i]
fns.push(exec_replace_task(task))
if (schedule_code_replacement_tasks) {
console.log("🤖 SVELTHREE > post-processing package: scheduling replacement tasks...")
for (let i = 0; i < replace_tasks.length; i++) {
const task = replace_tasks[i]
fns.push(exec_replace_task(task))
}
}

// schedule accessors-comments optimization in `d.ts` files
Expand Down
3 changes: 0 additions & 3 deletions src/lib/$app/env/index.ts

This file was deleted.

3 changes: 3 additions & 0 deletions src/lib/$app/environment/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
// Mimic SvelteKit's `$app/environment` foor non-SSR outputs in RollUp only and Vite only setups.

export const browser = true
67 changes: 67 additions & 0 deletions src/lib/ani/SvelthreeAni.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
import type { Scene, Object3D } from "three"
import type { SvelthreeAnimationFunction, SvelthreeAnimation } from "../types/types-extra"
import SvelthreeAnimationManager from "./SvelthreeAnimationManager"
import SvelthreeAnimationObjectFactory from "./SvelthreeAnimationObjectFactory"

export default class SvelthreeAni {
private ani_obj_factory: SvelthreeAnimationObjectFactory
private ani_manager: SvelthreeAnimationManager

constructor(
private scene: Scene,
private foo: Object3D,
private ani_fn: SvelthreeAnimationFunction,
private aniauto: boolean
) {
this.create_ani_manager()
}

private create_ani_manager(): void {
//if (verbose && log_dev) console.debug(...c_dev(c_name, "createAnimationManager!"))

if (!this.ani_manager) {
this.ani_obj_factory = new SvelthreeAnimationObjectFactory(this.ani_fn)
this.ani_manager = new SvelthreeAnimationManager(this.ani_obj_factory, this.aniauto, this.foo, this.scene)
}
}

public onCurrentSceneActiveChange(currentSceneActive: boolean): void {
this.ani_manager ? this.ani_manager.handleCurrentSceneStatus(currentSceneActive) : null
}

public getAnimation(): SvelthreeAnimation {
if (this.ani_manager) {
return this.ani_manager.getAnimation()
} else {
console.error("SVELTHREE > SvelthreeAnimation > getAnimation : missing SvelthreeAnimationManager!", {
ani_manager: this.ani_manager
})

return undefined
}
}

public destroyAnimation(): void {
//if (verbose && log_dev) console.debug(...c_dev(c_name, "destroyAnimation!"))
if (this.ani_manager) {
this.ani_manager.destroyAnimation()
} else {
if (this.ani_fn) {
console.error(
"SVELTHREE > SvelthreeAnimation > destroyAnimation : missing SvelthreeAnimationManager!",
{ ani_manager: this.ani_manager }
)
}
}
}

public startAnimation(): void {
if (this.ani_manager) {
this.ani_manager.startAnimation()
} else {
console.error("SVELTHREE > SvelthreeAnimation > startAni : missing SvelthreeAnimationManager!", {
ani_manager: this.ani_manager
})
}
}
}
71 changes: 0 additions & 71 deletions src/lib/ani/SvelthreeAnimation.ts

This file was deleted.

Loading

0 comments on commit cb2120f

Please sign in to comment.