Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feature: add putout #414

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,7 @@ are included so you can prototype your own plugins:
- [ESLint][] (v1, v2, v3)
- [jscodeshift][]
- [tslint][]
- [putout][]
- CSS
- [postcss][]
- MDX
Expand Down Expand Up @@ -138,6 +139,7 @@ node.
[typescript]: https://github.com/Microsoft/TypeScript/
[typescript-eslint-parser]: https://github.com/eslint/typescript-eslint-parser/
[tslint]: https://palantir.github.io/tslint/
[putout]: https://github.com/coderaiser/putout
[uglify-js]: https://github.com/mishoo/UglifyJS2
[webidl]: https://github.com/darobin/webidl2.js
[redot]: https://github.com/redotjs/redot
Expand Down
1 change: 1 addition & 0 deletions website/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@
"mini-css-extract-plugin": "^0.4.2",
"postcss-loader": "^3.0.0",
"progress-bar-webpack-plugin": "^1.9.3",
"putout": "^4.32.0",
"raw-loader": "^1.0.0",
"rimraf": "^2.5.4",
"style-loader": "^0.23.0",
Expand Down
17 changes: 17 additions & 0 deletions website/src/parsers/js/transformers/putout/codeExample.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
const {
types,
} = require('putout');

module.exports.report = (path) => `identifier ${path.node.name} should be reversed`;

module.exports.fix = (path) => {
path.node.name = path.node.name.split('').reverse().join('');
};

module.exports.traverse = ({push}) => {
return {
Identifier(path) {
push(path)
}
};
};
35 changes: 35 additions & 0 deletions website/src/parsers/js/transformers/putout/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
import compileModule from '../../../utils/compileModule';
import pkg from 'putout/package.json';

const ID = 'putout';
const name = 'putout';

export default {
id: ID,
displayName: name,
version: pkg.version,
homepage: pkg.homepage,

defaultParserID: 'babylon7',

loadTransformer(callback) {
require(
['putout/dist/putout.js'],
(putout) => callback({ putout })
);
},

transform({ putout }, transformCode, source) {
const plugin = compileModule(transformCode, {
require: () => putout,
});

const { code } = putout(source, {
plugins: [{
plugin,
}],
});

return code;
},
};
Loading