Skip to content
This repository has been archived by the owner on Mar 31, 2022. It is now read-only.
/ pAPRika Public archive

🌢 πŸ›  Automatic Program Repair made easy for both JS & TS!

Notifications You must be signed in to change notification settings

afonsojramos/pAPRika

Repository files navigation

pAPRika logo

pAPRika

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.

Usage

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:

  1. pAPRika: Spice this file - This command runs pAPRika on the current file.
  2. pAPRika: Spice all open files - This command runs pAPRika on all opened files, as such, it may become resource intensive.

Extension Settings

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.

Development

  • 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

Structure

.
β”œβ”€β”€ 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!