Skip to content
Open
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions packages/agoric-cli/src/sdk-package-names.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ export default [
"@agoric/deploy-script-support",
"@agoric/ertp",
"@agoric/eslint-config",
"@agoric/eslint-plugin",
"@agoric/fast-usdc",
"@agoric/governance",
"@agoric/import-manager",
Expand Down
10 changes: 10 additions & 0 deletions packages/eslint-plugin/eslint.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
import eslintPluginEslintPlugin from 'eslint-plugin-eslint-plugin';

export default [
{
plugins: {
'eslint-plugin': eslintPluginEslintPlugin,
},
extends: ['plugin:eslint-plugin/recommended'],
},
];
27 changes: 27 additions & 0 deletions packages/eslint-plugin/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
{
"name": "@agoric/eslint-plugin",
"version": "0.1.0",
"description": "ESLint plugin for Agoric best practices",
"main": "src/index.js",
"type": "module",
"files": [
"src"
],
"keywords": [
"eslint",
"eslintplugin",
"eslint-plugin"
],
"scripts": {
"build": "exit 0",
"test": "node --test **/*.test.*"
},
"peerDependencies": {
"eslint": "^8.57.1"
},
"devDependencies": {
"eslint": "^8.57.1",
"eslint-plugin-eslint-plugin": "^6.3.2"
},
"license": "Apache-2.0"
}
39 changes: 39 additions & 0 deletions packages/eslint-plugin/src/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
import fs from 'node:fs';
import { fileURLToPath } from 'node:url';

const pkg = JSON.parse(
fs.readFileSync(new URL('../package.json', import.meta.url), 'utf8'),
);

// Import rules
import dollarSign from './rules/dollar-sign.js';

const plugin = {
meta: {
name: pkg.name,
version: pkg.version,
},

// Rule definitions
rules: {
'dollar-sign': dollarSign,
},

// Recommended config
configs: {
recommended: [
{
plugins: {
// @ts-expect-error used before declaration
'@agoric': plugin,
},
rules: {
'@agoric/dollar-sign': 'error',
'@agoric/start-function-prelude': 'error',
},
},
],
},
};

export default plugin;
24 changes: 24 additions & 0 deletions packages/eslint-plugin/src/rules/dollar-sign.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
/** @type {import('eslint').Rule.RuleModule} */
export default {
meta: {
type: 'suggestion',
docs: {
description: 'Example rule that checks for dollar signs',
recommended: true,
},
schema: [], // no options
},

create(context) {
return {
Identifier(node) {
if (node.name.includes('$')) {
context.report({
node,
message: 'Avoid using $ in identifiers',
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is the dollar-sign avoidance an orthogonal improvement, or are these somehow coupled?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

it was part of the scaffold. a subsequent commit removed it

});
}
},
};
},
};
19 changes: 19 additions & 0 deletions packages/eslint-plugin/tests/rules/dollar-sign.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
import { RuleTester } from 'eslint';
import rule from '../../src/rules/dollar-sign.js';

const ruleTester = new RuleTester({
parserOptions: { ecmaVersion: 2022, sourceType: 'module' },
});

ruleTester.run('dollar-sign', rule, {
valid: [
{ code: 'const myVar = 1;' },
{ code: 'function test() { return true; }' },
],
invalid: [
{
code: 'const my$Var = 1;',
errors: [{ message: 'Avoid using $ in identifiers' }],
},
],
});
8 changes: 8 additions & 0 deletions packages/eslint-plugin/tsconfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
{
"extends": "../../tsconfig.json",
"compilerOptions": {},
"include": [
"src",
"test",
],
}
4 changes: 2 additions & 2 deletions packages/xsnap/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,9 @@
"postinstall": "npm run build:from-env",
"clean": "rm -rf xsnap-native/xsnap/build",
"lint": "yarn run -T run-s --continue-on-error 'lint:*'",
"lint:js": "eslint 'src/**/*.js' 'test/**/*.js' api.js",
"lint:eslint": "yarn run -T eslint 'src/**/*.js' 'test/**/*.js' api.js",
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why the change from lint:js to lint:eslint? I don't mind the change, but I am curious.

Copy link
Member Author

@turadg turadg Sep 17, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

the :eslint is for consistency with other packages. the yarn run -T is so the command can be run from CLI (rather tha only by run-s 'lint:*')

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good, thanks.

"lint:types": "yarn run -T tsc",
"lint-fix": "eslint --fix 'src/**/*.js' 'test/**/*.js' api.js",
"lint-fix": "yarn lint:eslint --fix",
"test": "ava",
"test:c8": "c8 --all ${C8_OPTIONS:-} ava",
"test:xs": "exit 0"
Expand Down
Loading