An Automatic Program Repair tool that attempts to fix small faults in your JS/TS code.
Developed by Afonso Ramos
TypeScript Compiler API
ยท
Mocha
Language Server Protocol
A prototype extension to Visual Studio Code, repairing JavaScript and TypeScript code and offering suggestions to the developers in real-time, using a mutation-based approach to Automated Program Repair in order to generate patches.
On each Test Function of Mocha (it
) leave an identifier to the function that is attempting to fix, like so: {mySubstring}
.
Example in JS:
i2
will show up as an error and suggest to be replaced with (i2 + 1)
function mySubstring(str, i1, i2) {
return str.substring(i1, i2)
}
describe('mySubstring Testing Suite', function () {
it('Test Name 1 {mySubstring}', function () {
assert.equal(mySubstring('This is a string', 1, 2), 'hi')
})
it('Test Name 2 {mySubstring}', function () {
assert.equal(mySubstring('This is a string', 6, 8), 's a')
})
})
It also supports Property-Based Testing:
>
will show up as an error and suggest to be replaced with >=
const fc = require('fast-check')
contains = (text, pattern) => text.indexOf(pattern) > 0
describe('properties', () => {
it('should always contain itself {contains}', () => {
fc.assert(fc.property(fc.string(), (text) => contains(text, text)))
})
it('should always contain its substrings {contains}', () => {
fc.assert(
fc.property(fc.string(), fc.string(), fc.string(), (a, b, c) => {
return contains(a + b + c, b)
})
)
})
})
For TypeScript
support it is required to have tsconfig.json
in the root folder.
There are four options for running pAPRika
, by saving the file, by opening a file, or by running either of the available commands:
pAPRika: Spice this file
- This command runs pAPRika on the current file.pAPRika: Spice all open files
- This command runs pAPRika on all opened files, as such, it may become resource intensive.
This extension contributes the following settings:
pAPRika.runOnOpen
: enable/disable running this extension when opening new files.pAPRika.runOnSave
: enable/disable running this extension when saving new files.
- Run
npm install
in this folder. This installs all necessary npm modules in both the client and server folder - Open VS Code on this folder.
- Press Ctrl+Shift+B to compile the client and server.
- Switch to the Debug view.
- Select
Launch Client
from the drop-down. - Run the launch config.
- If you want to debug the server as well use the launch configuration
Attach to Server
.
โโโ client // Language Client.
โ โโโ src
โ โ โโโ extension.ts // Language Client entry point.
โโโ examples // Examples of problems fixable with pAPRika.
โโโ pAPRika // pAPRika website.
โโโ server // Language Server.
โโโ src
โโโ server.ts // Language Server entry point.
Enjoy!