Skip to content

Commit 8f0b046

Browse files
authored
Add linting to babel plugin (#542)
1 parent a58e955 commit 8f0b046

File tree

2 files changed

+29
-28
lines changed

2 files changed

+29
-28
lines changed

packages/babel-plugin-react-server/package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818
"scripts": {
1919
"clean": "rm -rf lib npm-debug.log*",
2020
"build": "babel src -d lib",
21-
"test": "mocha --compilers js:babel-register",
21+
"test": "mocha --compilers js:babel-register && eslint src/",
2222
"test:watch": "npm run test -- --watch",
2323
"prepublish": "npm run clean && npm run build"
2424
},
Original file line numberDiff line numberDiff line change
@@ -1,34 +1,35 @@
11
import loggerSpec from 'react-server-module-tagger';
22
import path from 'path';
33

4-
module.exports = function({types: t }) {
5-
return {
6-
visitor: {
7-
Identifier(p, state) {
8-
const {node} = p;
9-
const {name, type} = node;
4+
module.exports = function() {
5+
return {
6+
visitor: {
7+
Identifier(p, state) {
8+
const {node} = p;
9+
const {name} = node;
1010

11-
const config = { trim: state.opts.trim };
12-
const parent = path.resolve(path.join(process.cwd(), '..')) + path.sep;
13-
const fp = this.file.opts.filename.replace(parent, '');
14-
const file = { path: fp };
15-
//TODO: Support labels
16-
const moduleTag = loggerSpec.bind({ file, config })(fp);
11+
const config = { trim: state.opts.trim };
12+
const parent = path.resolve(path.join(process.cwd(), '..')) + path.sep;
13+
const fp = this.file.opts.filename.replace(parent, '');
14+
const file = { path: fp };
1715

18-
let tokens;
19-
if (state.opts.tokens) {
20-
tokens = new Set(state.opts.tokens);
21-
} else {
22-
tokens = new Set(["__LOGGER__", "__CHANNEL__", "__CACHE__"]);
23-
}
16+
//TODO: Support labels
17+
const moduleTag = loggerSpec.bind({ file, config })(fp);
2418

25-
if (tokens.has(name)) {
26-
// this strikes me as a dirty, nasty hack. I think it would be better
27-
// to parse the object as json and coerce it to an array of
28-
// ObjectProperties to construct an ObjectExpression
29-
p.node.name = moduleTag;
30-
}
31-
}
32-
}
33-
};
19+
let tokens;
20+
if (state.opts.tokens) {
21+
tokens = new Set(state.opts.tokens);
22+
} else {
23+
tokens = new Set(["__LOGGER__", "__CHANNEL__", "__CACHE__"]);
24+
}
25+
26+
if (tokens.has(name)) {
27+
// this strikes me as a dirty, nasty hack. I think it would be better
28+
// to parse the object as json and coerce it to an array of
29+
// ObjectProperties to construct an ObjectExpression
30+
p.node.name = moduleTag;
31+
}
32+
},
33+
},
34+
};
3435
}

0 commit comments

Comments
 (0)