Skip to content

Commit

Permalink
feat: add missing transforms #10 (#3)
Browse files Browse the repository at this point in the history
* add draft for missing transforms

* add some test

* base idea to solve single param .send method

* move out recursiveParent to utils

* convert send to deprecated-signatures

* fix bug in send output file

* rename deprecated-signatures to v3-deprecated-signatures, cover json and jsonp cases, unify logic for 2 arguments with status and body

* add valid syntax cases for send method and add test cases

* split json and jsonp tests and add test cases with checking still supported syntax

* add vscode config to gitignore

* change deprecated-signatures prefix to v4

* update transform config for v4-deprecated-signatures

---------

Co-authored-by: Filip Kudła <[email protected]>
Co-authored-by: Sebastian Beltran <[email protected]>
  • Loading branch information
3 people authored Nov 18, 2024
1 parent e64c5d1 commit 4fb1e92
Show file tree
Hide file tree
Showing 13 changed files with 503 additions and 23 deletions.
5 changes: 4 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -25,4 +25,7 @@ yarn-error.log*

*.d.ts
*.js
*.js.map
*.js.map

# VSCode
.vscode
6 changes: 5 additions & 1 deletion config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,5 +9,9 @@ export const TRANSFORM_OPTIONS = [
value: 'pluralized-methods',
version: '5.0.0',
},
//{ description: 'Transform the deprecated signatures in Express v4', value: 'signature-deprecated', version: '5.0.0' },
{
description: 'Transform the deprecated signatures in Express v4',
value: 'v4-deprecated-signatures',
version: '5.0.0'
},
]
3 changes: 3 additions & 0 deletions transforms/__test__/v4-deprecated-signatures.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
import { testSpecBuilder } from './util'

testSpecBuilder('v4-deprecated-signatures')
57 changes: 57 additions & 0 deletions transforms/__testfixtures__/v4-deprecated-signatures/json.input.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
import express from "express";

const app = express();

app.get("/json", function (req, res) {
res.json({ user: "Username", isValid: true }, 200);
});

app.get("/json", function (req, response) {
response.json({ user: "Username", isValid: true }, 200);
});

app.get("/json", (req, res) => {
res.json({ user: "Username", isValid: true }, 200);
});

app.get("/json", (req, response) => {
response.json({ user: "Username", isValid: true }, 200);
});

app.get("/json", function (req, res) {
res.json({}, 200);
});

app.get("/json", function (req, response) {
response.json({}, 200);
});

app.get("/json", (req, res) => {
res.json({}, 200);
});

app.get("/json", (req, response) => {
response.json({}, 200);
});

// Still valid syntax -- START
app.get("/json", function (req, res) {
res.json(null)
res.json({ user: 'tobi' })
})

app.get("/json", function (req, response) {
response.json(null)
response.json({ user: 'tobi' })
})

app.get("/json", function (req, res) {
res.json(null)
res.json({ user: 'tobi' })
})

app.get("/json", function (req, response) {
response.json(null)
response.json({ user: 'tobi' })
})
// Still valid syntax -- END
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
import express from "express";

const app = express();

app.get("/json", function (req, res) {
res.status(200).json({ user: "Username", isValid: true });
});

app.get("/json", function (req, response) {
response.status(200).json({ user: "Username", isValid: true });
});

app.get("/json", (req, res) => {
res.status(200).json({ user: "Username", isValid: true });
});

app.get("/json", (req, response) => {
response.status(200).json({ user: "Username", isValid: true });
});

app.get("/json", function (req, res) {
res.status(200).json({});
});

app.get("/json", function (req, response) {
response.status(200).json({});
});

app.get("/json", (req, res) => {
res.status(200).json({});
});

app.get("/json", (req, response) => {
response.status(200).json({});
});

// Still valid syntax -- START
app.get("/json", function (req, res) {
res.json(null)
res.json({ user: 'tobi' })
})

app.get("/json", function (req, response) {
response.json(null)
response.json({ user: 'tobi' })
})

app.get("/json", function (req, res) {
res.json(null)
res.json({ user: 'tobi' })
})

app.get("/json", function (req, response) {
response.json(null)
response.json({ user: 'tobi' })
})
// Still valid syntax -- END
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
import express from "express";

const app = express();

app.get("/jsonp", function (req, res) {
res.jsonp({ user: "Username", isValid: true }, 200);
});

app.get("/jsonp", function (req, response) {
response.jsonp({ user: "Username", isValid: true }, 200);
});

app.get("/jsonp", (req, res) => {
res.jsonp({ user: "Username", isValid: true }, 200);
});

app.get("/jsonp", (req, response) => {
response.jsonp({ user: "Username", isValid: true }, 200);
});

app.get("/jsonp", function (req, res) {
res.jsonp({}, 200);
});

app.get("/jsonp", function (req, response) {
response.jsonp({}, 200);
});

app.get("/jsonp", (req, res) => {
res.jsonp({}, 200)
});

app.get("/jsonp", (req, response) => {
response.jsonp({}, 200)
});

// Still valid syntax -- START
app.get("/jsonp", function (req, res) {
res.jsonp(null)
res.jsonp({ user: 'tobi' })
})

app.get("/jsonp", function (req, response) {
response.jsonp(null)
response.jsonp({ user: 'tobi' })
})

app.get("/jsonp", function (req, res) {
res.jsonp(null)
res.jsonp({ user: 'tobi' })
})

app.get("/jsonp", function (req, response) {
response.jsonp(null)
response.jsonp({ user: 'tobi' })
})
// Still valid syntax -- END
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
import express from "express";

const app = express();

app.get("/jsonp", function (req, res) {
res.status(200).jsonp({ user: "Username", isValid: true });
});

app.get("/jsonp", function (req, response) {
response.status(200).jsonp({ user: "Username", isValid: true });
});

app.get("/jsonp", (req, res) => {
res.status(200).jsonp({ user: "Username", isValid: true });
});

app.get("/jsonp", (req, response) => {
response.status(200).jsonp({ user: "Username", isValid: true });
});

app.get("/jsonp", function (req, res) {
res.status(200).jsonp({});
});

app.get("/jsonp", function (req, response) {
response.status(200).jsonp({});
});

app.get("/jsonp", (req, res) => {
res.status(200).jsonp({})
});

app.get("/jsonp", (req, response) => {
response.status(200).jsonp({})
});

// Still valid syntax -- START
app.get("/jsonp", function (req, res) {
res.jsonp(null)
res.jsonp({ user: 'tobi' })
})

app.get("/jsonp", function (req, response) {
response.jsonp(null)
response.jsonp({ user: 'tobi' })
})

app.get("/jsonp", function (req, res) {
res.jsonp(null)
res.jsonp({ user: 'tobi' })
})

app.get("/jsonp", function (req, response) {
response.jsonp(null)
response.jsonp({ user: 'tobi' })
})
// Still valid syntax -- END
61 changes: 61 additions & 0 deletions transforms/__testfixtures__/v4-deprecated-signatures/send.input.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
import express from "express";

const app = express();

app.get("/send", function (req, res) {
res.send(200, { hello: "world" });
});

app.get("/send", function (req, response) {
response.send(200, "Hello World");
});

app.get("/send", function (req, res) {
res.send(200);
});

app.get("/send", function (req, res) {
res.send(200, true);
});

app.get("/send", (req, res) => {
res.send(200, { hello: "world" });
});

app.get("/send", (req, res) => {
res.send(200);
});

app.get("/send", (req, response) => {
response.send(200);
});

app.get("/send", (req, response) => {
response.send(200, true);
});

// Still valid syntax -- START
app.get("/send", function (req, res) {
res.send(Buffer.from('whoop'));
res.send({ some: 'json' });
res.send('<p>some html</p>');
});

app.get("/send", function (req, response) {
response.send(Buffer.from('whoop'));
response.send({ some: 'json' });
response.send('<p>some html</p>');
});

app.get("/send", (req, response) => {
response.send(Buffer.from('whoop'));
response.send({ some: 'json' });
response.send('<p>some html</p>');
});

app.get("/send", (req, res) => {
res.send(Buffer.from('whoop'));
res.send({ some: 'json' });
res.send('<p>some html</p>');
});
// Still valid syntax -- END
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
import express from "express";

const app = express();

app.get("/send", function (req, res) {
res.status(200).send({ hello: "world" });
});

app.get("/send", function (req, response) {
response.status(200).send("Hello World");
});

app.get("/send", function (req, res) {
res.sendStatus(200);
});

app.get("/send", function (req, res) {
res.status(200).send(true);
});

app.get("/send", (req, res) => {
res.status(200).send({ hello: "world" });
});

app.get("/send", (req, res) => {
res.sendStatus(200);
});

app.get("/send", (req, response) => {
response.sendStatus(200);
});

app.get("/send", (req, response) => {
response.status(200).send(true);
});

// Still valid syntax -- START
app.get("/send", function (req, res) {
res.send(Buffer.from('whoop'));
res.send({ some: 'json' });
res.send('<p>some html</p>');
});

app.get("/send", function (req, response) {
response.send(Buffer.from('whoop'));
response.send({ some: 'json' });
response.send('<p>some html</p>');
});

app.get("/send", (req, response) => {
response.send(Buffer.from('whoop'));
response.send({ some: 'json' });
response.send('<p>some html</p>');
});

app.get("/send", (req, res) => {
res.send(Buffer.from('whoop'));
res.send({ some: 'json' });
res.send('<p>some html</p>');
});
// Still valid syntax -- END
Loading

0 comments on commit 4fb1e92

Please sign in to comment.