Skip to content

Commit 5f82304

Browse files
committed
add test case
1 parent 54b3f44 commit 5f82304

File tree

4 files changed

+80
-11
lines changed

4 files changed

+80
-11
lines changed

eslint.config.mjs

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
// Import necessary modules for flat config
2+
import tsParser from "@typescript-eslint/parser";
3+
// Import the local plugin using ES Module syntax
4+
import localPlugin from "./index.js"; // Assumes index.js is the entry point
5+
6+
const allPluginRules = {};
7+
const pluginName = "assemblyscript"; // Use the plugin name defined in bash
8+
9+
// Access rules from the default export of the plugin module
10+
if (localPlugin && localPlugin.rules) {
11+
for (const ruleName in localPlugin.rules) {
12+
// Construct the full rule name: 'plugin-name/rule-name'
13+
allPluginRules[`${pluginName}/${ruleName}`] = "warn"; // Set default severity
14+
}
15+
} else {
16+
console.warn(
17+
`Plugin '${pluginName}' loaded from ./index.js does not seem to export rules correctly.`
18+
);
19+
}
20+
21+
// Export the flat config array
22+
export default [
23+
{
24+
// Apply to TypeScript files in the target directory
25+
files: ["**/*.ts"],
26+
languageOptions: {
27+
parser: tsParser,
28+
parserOptions: {
29+
ecmaVersion: "latest",
30+
sourceType: "module",
31+
},
32+
},
33+
// Define the plugin using the imported object
34+
plugins: {
35+
[pluginName]: localPlugin,
36+
},
37+
// Apply the dynamically generated rules
38+
rules: allPluginRules,
39+
},
40+
];

lint-target.sh

Lines changed: 4 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,9 @@
44

55
set -e # Exit immediately if a command exits with a non-zero status.
66

7-
TARGET_DIR="$1"
7+
TARGET_DIR="sample_cases/usecase-wasm-vehicle-status-25/source"
88
# Use .mjs for ES Module flat config
9-
CONFIG_FILE=".eslintrc.tmp.mjs"
9+
CONFIG_FILE="eslint.config.mjs"
1010
PLUGIN_NAME="assemblyscript" # Plugin name prefix used in rules
1111

1212
# Check if target directory is provided
@@ -22,18 +22,12 @@ if [ ! -d "$TARGET_DIR" ]; then
2222
fi
2323

2424
# Create a temporary ESLint flat config file (.mjs)
25-
cat > "$CONFIG_FILE" << EOL
25+
cat >"$CONFIG_FILE" <<EOL
2626
// Import necessary modules for flat config
27-
import path from 'path';
28-
import { fileURLToPath } from 'url';
2927
import tsParser from '@typescript-eslint/parser';
3028
// Import the local plugin using ES Module syntax
3129
import localPlugin from './index.js'; // Assumes index.js is the entry point
3230
33-
// Helper to get current directory in ES Modules
34-
const __filename = fileURLToPath(import.meta.url);
35-
const __dirname = path.dirname(__filename);
36-
3731
const allPluginRules = {};
3832
const pluginName = '${PLUGIN_NAME}'; // Use the plugin name defined in bash
3933
@@ -83,7 +77,7 @@ else
8377
fi
8478

8579
# Clean up the temporary config file
86-
rm "$CONFIG_FILE"
80+
# rm "$CONFIG_FILE"
8781
echo "Removed temporary config file: $CONFIG_FILE"
8882

8983
exit $EXIT_CODE

package.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,8 @@
2727
],
2828
"scripts": {
2929
"build": "npx tsc --build ./tsconfig.json",
30-
"test": "./test-lint.sh"
30+
"test": "./test-lint.sh",
31+
"lint": "npx eslint test_case/hello.ts"
3132
},
3233
"peerDependencies": {
3334
"eslint": ">=8.0.0"

test_case/hello.ts

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
import { DelayType } from "@utils/time-utils";
2+
3+
export namespace TimingConfig {
4+
export const defaultCooldownStandard: u32 = DelayType.STANDARD;
5+
/**
6+
* Cooldown duration for urban positioning scenarios
7+
*/
8+
export const urbanPositioningCooldown = DelayType.SHORT;
9+
/**
10+
* Cooldown duration for high-speed positioning scenarios
11+
*/
12+
export const highSpeedPositioningCooldown = DelayType.LONG;
13+
}
14+
15+
/**
16+
* Distance-based emission strategy
17+
*/
18+
export class DistanceBasedDeliveryStrategy implements EmissionStrategy {
19+
private context: SystemContext;
20+
constructor(context: SystemContext) {
21+
this.context = context;
22+
}
23+
isEmissionConditionMet(emissionGroup: EmissionGroup): boolean {
24+
void emissionGroup;
25+
return true;
26+
}
27+
determineCooldown(emissionGroup: EmissionGroup): DelayType {
28+
void emissionGroup;
29+
return this.context.getCurrentZone().isPresent() &&
30+
this.context.getCurrentZone().get() === ZoneType.RESIDENTIAL
31+
? DelayType.SHORT
32+
: DelayType.NEVER;
33+
}
34+
}

0 commit comments

Comments
 (0)