Skip to content

Commit

Permalink
dev: Experiment with ESTree (#2438)
Browse files Browse the repository at this point in the history
  • Loading branch information
Jason3S authored Feb 12, 2022
1 parent e4fc3fb commit 58e92ee
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 7 deletions.
9 changes: 7 additions & 2 deletions packages/cspell-eslint-plugin/samples/sampleESM.mjs
Original file line number Diff line number Diff line change
@@ -1,8 +1,13 @@
import { promises as fs } from 'fs';

function mapDir(dir) {
return `type: ${dir.isFile ? 'F' : ' '}${dir.isDirectory() ? 'D' :' '} name: ${dir.name}`;
}

async function listFiles() {
const dir = await fs.readdir('.');
console.log(dir.join('\n'));
const dirs = await fs.readdir('.', { withFileTypes: true });
const entries = dirs.map(mapDir);
console.log(entries.join('\n'));
}

listFiles();
12 changes: 9 additions & 3 deletions packages/cspell-eslint-plugin/scope.md
Original file line number Diff line number Diff line change
@@ -1,8 +1,14 @@
# Code Scopes

| Scope | Meaning |
| ----------- | ------------------------------ |
| `source.ts` | Matches extension of the file. |
| Scope | Meaning |
| --------------------------- | ------------------------------ |
| `source.ts` | Matches extension of the file. |
| `string.quoted.single.ts` | Single quote string |
| `string.quoted.double.ts` | Double quote string |
| `string.template.js` | Template string |
| `entity.name.function.ts` | Function name |
| `entity.name.type.class.ts` | |
| `meta.class.ts` | |

References:

Expand Down
16 changes: 14 additions & 2 deletions packages/cspell-eslint-plugin/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -76,14 +76,26 @@ scope: ${context.getScope().type}
}
if (node.type === 'MemberExpression') {
const extra = node.property === child ? 'property' : node.object === child ? 'object' : '';
return [node.type, extra].join('.');
return node.type + '.' + extra;
}
if (node.type === 'ArrowFunctionExpression') {
const extra = node.body === child ? 'body' : 'param';
return node.type + '.' + extra;
}
if (node.type === 'FunctionDeclaration') {
const extra = node.id === child ? 'id' : node.body === child ? 'body' : 'params';
return node.type + '.' + extra;
}
if (node.type === 'ClassDeclaration' || node.type === 'ClassExpression') {
const extra = node.id === child ? 'id' : node.body === child ? 'body' : 'superClass';
return node.type + '.' + extra;
}
return node.type;
}

function inheritance(node: Node) {
const a = [...context.getAncestors(), node];
return a.map(mapNode).join('.');
return a.map(mapNode).join(' ');
}
}

Expand Down

0 comments on commit 58e92ee

Please sign in to comment.