Skip to content

Commit dad6786

Browse files
author
Stefan Lau
committed
Put breaking change from 1.3.0 behind a flag
1 parent 70efd65 commit dad6786

File tree

5 files changed

+42
-17
lines changed

5 files changed

+42
-17
lines changed

README.md

+17
Original file line numberDiff line numberDiff line change
@@ -104,13 +104,30 @@ Now, in your code:
104104
export default function variableName;
105105
```
106106

107+
If you also want to match exported function calls you can use the third option (a boolean flag).
108+
109+
```json
110+
"filenames/match-exported": [ 2, null, null, true ]
111+
```
112+
113+
Now, in your code:
114+
115+
```js
116+
// Considered problem only if file isn't named functionName.js or functionName/index.js
117+
export default functionName();
118+
```
119+
107120
### Don't allow index.js files (no-index)
108121

109122
Having a bunch of `index.js` files can have negative influence on developer experience, e.g. when
110123
opening files by name. When enabling this rule. `index.js` files will always be considered a problem.
111124

112125
## Changelog
113126

127+
#### 1.3.1
128+
129+
- Put breaking change from `1.3.0` behind a flag
130+
114131
#### 1.3.0
115132

116133
- Support call expressions as named exports

lib/common/getExportedName.js

+5-5
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
function getNodeName(node) {
1+
function getNodeName(node, options) {
22
if (node.type === "Identifier") {
33
return node.name;
44
}
@@ -7,18 +7,18 @@ function getNodeName(node) {
77
return node.id.name;
88
}
99

10-
if (node.type === "CallExpression" && node.callee.type === "Identifier") {
10+
if (options[2] && node.type === "CallExpression" && node.callee.type === "Identifier") {
1111
return node.callee.name;
1212
}
1313
}
1414

15-
module.exports = function getExportedName(programNode) {
15+
module.exports = function getExportedName(programNode, options) {
1616
for (var i = 0; i < programNode.body.length; i += 1) {
1717
var node = programNode.body[i];
1818

1919
// export default ...
2020
if (node.type === "ExportDefaultDeclaration") {
21-
return getNodeName(node.declaration);
21+
return getNodeName(node.declaration, options);
2222
}
2323

2424
// module.exports = ...
@@ -30,7 +30,7 @@ module.exports = function getExportedName(programNode) {
3030
node.expression.left.property.type === "Identifier" &&
3131
node.expression.left.property.name === "exports"
3232
) {
33-
return getNodeName(node.expression.right);
33+
return getNodeName(node.expression.right, options);
3434
}
3535
}
3636
};

lib/rules/match-exported.js

+5-2
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,7 @@ module.exports = function(context) {
7575
absoluteFilename = path.resolve(filename),
7676
parsed = parseFilename(absoluteFilename),
7777
shouldIgnore = isIgnoredFilename(filename),
78-
exportedName = getExportedName(node),
78+
exportedName = getExportedName(node, context.options),
7979
isExporting = Boolean(exportedName),
8080
expectedExport = getStringToCheckAgainstExport(parsed, replacePattern),
8181
transformedNames = transform(exportedName, transforms),
@@ -115,6 +115,9 @@ module.exports.schema = [
115115
]
116116
},
117117
{
118-
type: "string"
118+
type: [ "string", "null" ]
119+
},
120+
{
121+
type: [ "boolean", "null" ]
119122
}
120123
];

package.json

+1-2
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "eslint-plugin-filenames",
3-
"version": "1.3.0",
3+
"version": "1.3.1",
44
"description": "Eslint rule for consistent filenames.",
55
"main": "index.js",
66
"scripts": {
@@ -17,7 +17,6 @@
1717
"lodash.snakecase": "4.1.1",
1818
"lodash.upperfirst": "4.3.1"
1919
},
20-
2120
"devDependencies": {
2221
"chai": "3.5.0",
2322
"coveralls": "2.13.0",

test/rules/match-exported.js

+14-8
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ ruleTester.run("lib/rules/match-exported", exportedRule, {
6565
},
6666
{
6767
code: exportedCalledFunctionCode,
68-
filename: "/some/dir/foo.js"
68+
filename: "/some/dir/bar.js"
6969
},
7070
{
7171
code: exportedJsxFunctionCode,
@@ -152,13 +152,6 @@ ruleTester.run("lib/rules/match-exported", exportedRule, {
152152
{ message: "Filename 'bar' must match the exported name 'foo'.", column: 1, line: 1 }
153153
]
154154
},
155-
{
156-
code: exportedCalledFunctionCode,
157-
filename: "/some/dir/bar.js",
158-
errors: [
159-
{ message: "Filename 'bar' must match the exported name 'foo'.", column: 1, line: 1 }
160-
]
161-
},
162155
{
163156
code: exportedJsxFunctionCode,
164157
filename: "/some/dir/bar.js",
@@ -295,6 +288,11 @@ ruleTester.run("lib/rules/match-exported with configuration", exportedRule, {
295288
filename: "/some/dir/Foo.react.js",
296289
parserOptions: { ecmaVersion: 6, sourceType: "module", ecmaFeatures: { jsx: true } },
297290
options: [null, "\\.react$"]
291+
},
292+
{
293+
code: exportedCalledFunctionCode,
294+
filename: "/some/dir/foo.js",
295+
options: [null, null, true]
298296
}
299297
],
300298

@@ -360,6 +358,14 @@ ruleTester.run("lib/rules/match-exported with configuration", exportedRule, {
360358
errors: [
361359
{ message: "The directory 'Foo.react' must be named 'Foo', after the exported value of its index file.", column: 1, line: 1 }
362360
]
361+
},
362+
{
363+
code: exportedCalledFunctionCode,
364+
filename: "/some/dir/bar.js",
365+
errors: [
366+
{ message: "Filename 'bar' must match the exported name 'foo'.", column: 1, line: 1 }
367+
],
368+
options: [null, null, true]
363369
}
364370
]
365371
});

0 commit comments

Comments
 (0)