-
Notifications
You must be signed in to change notification settings - Fork 254
custom eslint plugin that fixes typedef imports #11949
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Changes from 2 commits
a7b3975
2561a96
6adc2ae
6f8cea5
60470fb
146d692
dda8e07
7932109
0395b45
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| 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'], | ||
| }, | ||
| ]; |
| 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" | ||
| } |
| 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; |
| 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', | ||
| }); | ||
| } | ||
| }, | ||
| }; | ||
| }, | ||
| }; | ||
| 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' }], | ||
| }, | ||
| ], | ||
| }); |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,8 @@ | ||
| { | ||
| "extends": "../../tsconfig.json", | ||
| "compilerOptions": {}, | ||
| "include": [ | ||
| "src", | ||
| "test", | ||
| ], | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -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", | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Why the change from There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. the There was a problem hiding this comment. Choose a reason for hiding this commentThe 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" | ||
|
|
||
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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