-
Notifications
You must be signed in to change notification settings - Fork 9
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Refactor flAST to ESM, Refactor Tests to Node's Test Runner (#28)
- Update dependencies - Refactor code to ESM - Replace custom test runner with Node's builting test runner - Add more tests to increase coverage - Add coverage report using npm run test:coverage - Fix Husky's pre-commit hook
- Loading branch information
1 parent
c198e72
commit 46bb65e
Showing
25 changed files
with
689 additions
and
965 deletions.
There are no files selected for viewing
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,2 @@ | ||
#!/usr/bin/env sh | ||
. "$(dirname -- "$0")/_/husky.sh" | ||
|
||
npm test | ||
npx eslint . |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -27,7 +27,7 @@ npm install flast | |
``` | ||
|
||
### Clone The Repo | ||
Requires Node 16 or newer. | ||
Requires Node 18 or newer. | ||
```bash | ||
git clone [email protected]:PerimeterX/flast.git | ||
cd flast | ||
|
@@ -165,7 +165,7 @@ const tree = [ | |
### flAST | ||
|
||
```javascript | ||
const {generateFlatAST, generateCode} = require('flast'); | ||
import {generateFlatAST, generateCode} from 'flast'; | ||
const ast = generateFlatAST(`console.log('flAST')`); | ||
const reconstructedCode = generateCode(ast[0]); // rebuild from root node | ||
``` | ||
|
@@ -197,7 +197,7 @@ const generateCodeDefaultOptions = { | |
### Arborist | ||
|
||
```javascript | ||
const {generateFlatAST, generateCode, Arborist} = require('flast'); | ||
import {generateFlatAST, generateCode, Arborist} from 'flast'; | ||
const ast = generateFlatAST(`console.log('Hello' + ' ' + 'there!');`); | ||
const replacements = { | ||
'Hello': 'General', | ||
|
@@ -213,8 +213,8 @@ ast.filter(n => n.type === 'Literal' && replacements[n.value]).forEach(n => arbo | |
const numberOfChangesMade = arborist.applyChanges(); | ||
console.log(generateCode(arborist.ast[0])); // console.log('General' + ' ' + 'Kenobi'); | ||
``` | ||
The Arborist can be called with an extra argument - logFunc - which can be used to log | ||
inside the arborist. | ||
The Arborist can be called with an extra argument - logFunc - which can be used to override the log | ||
function inside the arborist. | ||
|
||
## How to Contribute | ||
To contribute to this project see our [contribution guide](CONTRIBUTING.md) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
import globals from "globals"; | ||
import path from "node:path"; | ||
import { fileURLToPath } from "node:url"; | ||
import js from "@eslint/js"; | ||
import { FlatCompat } from "@eslint/eslintrc"; | ||
|
||
const __filename = fileURLToPath(import.meta.url); | ||
const __dirname = path.dirname(__filename); | ||
const compat = new FlatCompat({ | ||
baseDirectory: __dirname, | ||
recommendedConfig: js.configs.recommended, | ||
allConfig: js.configs.all | ||
}); | ||
|
||
export default [{ | ||
ignores: ["**/*tmp*/", "**/*tmp*.*", "eslint.config.js", "node_modules/"], | ||
}, ...compat.extends("eslint:recommended"), { | ||
languageOptions: { | ||
globals: { | ||
...globals.browser, | ||
...globals.node, | ||
...globals.commonjs, | ||
}, | ||
|
||
ecmaVersion: "latest", | ||
sourceType: "module", | ||
}, | ||
|
||
rules: { | ||
indent: ["error", "tab", { | ||
SwitchCase: 1, | ||
}], | ||
|
||
"linebreak-style": ["error", "unix"], | ||
|
||
quotes: ["error", "single", { | ||
allowTemplateLiterals: true, | ||
}], | ||
|
||
semi: ["error", "always"], | ||
"no-empty": ["off"], | ||
}, | ||
}]; |
Oops, something went wrong.