Skip to content

Commit

Permalink
feature: add putout
Browse files Browse the repository at this point in the history
  • Loading branch information
coderaiser committed Jun 19, 2019
1 parent b927f31 commit 3368afb
Show file tree
Hide file tree
Showing 5 changed files with 493 additions and 4 deletions.
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.31.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

0 comments on commit 3368afb

Please sign in to comment.