Skip to content

Commit

Permalink
add many more checks to ESlint
Browse files Browse the repository at this point in the history
  • Loading branch information
ForestOfLight committed Jan 26, 2025
1 parent 21c9914 commit e8f4297
Show file tree
Hide file tree
Showing 4 changed files with 64 additions and 12 deletions.
3 changes: 1 addition & 2 deletions Canopy [BP]/scripts/src/rules/allowBubbleColumnPlacement.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,7 @@ new Rule({
world.beforeEvents.playerPlaceBlock.subscribe((event) => {
if (!event.player || !Rule.getNativeValue('allowBubbleColumnPlacement')) return;
system.run(() => {
if (event.player.getComponent('equippable').getEquipment('Mainhand')?.typeId === 'minecraft:bubble_column') {
if (event.player.getComponent('equippable').getEquipment('Mainhand')?.typeId === 'minecraft:bubble_column')
world.structureManager.place('mystructure:bubble_column', event.dimension, event.block.location);
}
});
});
7 changes: 5 additions & 2 deletions Canopy [BP]/scripts/src/rules/infodisplay/tps.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,12 @@
import InfoDisplayElement from './InfoDisplayElement.js';
import { DataTPS } from 'src/tps';
import { TicksPerSecond } from '@minecraft/server';

const DISPLAY_LINE = 4;

class TPS extends InfoDisplayElement {
constructor() {
super('tps', { translate: 'rules.infoDisplay.tps' }, 4, true);
super('tps', { translate: 'rules.infoDisplay.tps' }, DISPLAY_LINE, true);
}

getFormattedDataOwnLine() {
Expand All @@ -16,7 +19,7 @@ class TPS extends InfoDisplayElement {

getTPS() {
const tps = DataTPS.tps.toFixed(1);
return tps >= 20 ? a20.0` : `§c${tps}`;
return tps >= TicksPerSecond ? a${TicksPerSecond}.0` : `§c${tps}`;
}
}

Expand Down
12 changes: 7 additions & 5 deletions Canopy [BP]/scripts/src/tps.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
import { system } from '@minecraft/server'
import { system, TicksPerSecond} from '@minecraft/server'

const MS_PER_SECOND = 1000;

const DataTPS = {
tps: 0,
Expand All @@ -9,17 +11,17 @@ const DataTPS = {
msptArray: [],

tpsToMspt(tps) {
return 1000 / tps;
return MS_PER_SECOND / tps;
},

msptToTps(mspt) {
return 1000 / mspt;
return MS_PER_SECOND / mspt;
}
}

system.runInterval(() => {
if (DataTPS.tpsArray.length >= 20) DataTPS.tpsArray.shift();
if (DataTPS.msptArray.length >= 20) DataTPS.msptArray.shift();
if (DataTPS.tpsArray.length >= TicksPerSecond) DataTPS.tpsArray.shift();
if (DataTPS.msptArray.length >= TicksPerSecond) DataTPS.msptArray.shift();
DataTPS.mspt = Date.now() - DataTPS.lastTick;
DataTPS.tpsArray.push(DataTPS.msptToTps(DataTPS.mspt));
DataTPS.tps = DataTPS.tpsArray.reduce((a,b) => a + b) / DataTPS.tpsArray.length;
Expand Down
54 changes: 51 additions & 3 deletions eslint.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,9 @@ import { includeIgnoreFile } from "@eslint/compat";
import path from "node:path";
import { fileURLToPath } from "node:url";

const __filename = fileURLToPath(import.meta.url);
const __dirname = path.dirname(__filename);
const gitignorePath = path.resolve(__dirname, ".gitignore");
const filename = fileURLToPath(import.meta.url);
const dirname = path.dirname(filename);
const gitignorePath = path.resolve(dirname, ".gitignore");

/** @type {import('eslint').Linter.Config[]} */
export default [
Expand All @@ -16,6 +16,7 @@ export default [
'**/scripts/lib/mt.js',
'**/scripts/lib/ipc/',
'**/scripts/lib/SRCItemDatabase.js',
'**/__tests__/',
]
},
js.configs.recommended,
Expand All @@ -28,4 +29,51 @@ export default [
}
},
includeIgnoreFile(gitignorePath),
{
rules: {
"no-constructor-return": "error",
"no-duplicate-imports": "error",
"no-template-curly-in-string": "error",
"no-unreachable-loop": "error",
"no-use-before-define": "error",
"no-useless-assignment": "error",
// Suggestions:
"arrow-body-style": "error",
"block-scoped-var": "error",
"camelcase": [ "warn", { "ignoreImports": true } ],
"curly": ["error", "multi", "consistent"],
"default-case": "error",
"default-case-last": "error",
"eqeqeq": "error",
"func-style": ["error", "declaration", { "allowArrowFunctions": true }],
"max-classes-per-file": ["error", 1], // { ignoreExpressions: true }
"max-depth": ["warn"],
"max-lines": ["warn"],
"max-lines-per-function": ["warn"],
"max-params": ["warn"],
"new-cap": "error",
"no-else-return": "error",
"no-lonely-if": "error",
"no-magic-numbers": ["error", { "ignore": [0, 1], "ignoreArrayIndexes": true } ],
"no-negated-condition": "error",
"no-nested-ternary": "error",
"no-return-assign": "error",
"no-shadow": "error",
"no-throw-literal": "error",
"no-undefined": "error",
"no-underscore-dangle": "error",
"no-unneeded-ternary": "error",
"no-useless-computed-key": "error",
"no-useless-concat": "error",
"no-useless-constructor": "error",
"no-useless-return": "error",
"no-var": "error",
"no-warning-comments": "warn",
"one-var": ["error", "never"],
"operator-assignment": "error",
"prefer-const": "error",
"require-await": "error",
"yoda": "error",
}
}
];

0 comments on commit e8f4297

Please sign in to comment.