Skip to content

Commit ac9fad9

Browse files
le0nikKent C. Dodds
authored andcommitted
fix(loaders[i].loaders): add descriptive error message (#126)
1 parent b8c04ba commit ac9fad9

File tree

2 files changed

+21
-5
lines changed

2 files changed

+21
-5
lines changed

src/properties/module/index.js

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,12 @@ const LOADER_EXCLUDE_FORBIDDEN = oneLine`
2727
which might inadvertently slow your build down. Use \`include\` instead. (loader-prefer-include)
2828
`
2929

30+
const LOADER_IN_LOADERS_MESSAGE = oneLine`
31+
at position {{pos}} must be a String or an Object with properties:
32+
"loader": (String, required),
33+
"query": (Object, optional)
34+
`
35+
3036
const conditionSchema = Joi.array().items([
3137
Joi.string(),
3238
Joi.object().type(RegExp),
@@ -46,7 +52,13 @@ const loaderSchemaFn = ({ rules }) => {
4652
loader: Joi.string().required(),
4753
query: Joi.object(),
4854
})
49-
),
55+
).options({
56+
language: {
57+
array: {
58+
includes: LOADER_IN_LOADERS_MESSAGE,
59+
},
60+
},
61+
}),
5062
})
5163
.xor('loaders', 'loader')
5264
.nand('loaders', 'query')

src/properties/module/index.test.js

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,8 @@
1-
import schemaFn, { CONDITION_MESSAGE, LOADERS_QUERY_MESSAGE } from './index'
1+
import schemaFn, {
2+
CONDITION_MESSAGE,
3+
LOADERS_QUERY_MESSAGE,
4+
LOADER_IN_LOADERS_MESSAGE,
5+
} from './index'
26
import { allValid, allInvalid } from '../../../test/utils'
37

48
const validModuleConfigs = [
@@ -96,7 +100,7 @@ const invalidModuleConfigs = [
96100
],
97101
},
98102
error: {
99-
message: '"loaders" at position 0 does not match any of the allowed types',
103+
message: LOADER_IN_LOADERS_MESSAGE,
100104
path: 'loaders.0.loaders.0',
101105
},
102106
},
@@ -177,7 +181,7 @@ const invalidModuleConfigs = [
177181
}],
178182
},
179183
error: {
180-
message: '"loaders" at position 0 does not match any of the allowed types',
184+
message: LOADER_IN_LOADERS_MESSAGE,
181185
path: 'loaders.0.loaders.0',
182186
},
183187
},
@@ -193,7 +197,7 @@ const invalidModuleConfigs = [
193197
}],
194198
},
195199
error: {
196-
message: '"loaders" at position 0 does not match any of the allowed types',
200+
message: LOADER_IN_LOADERS_MESSAGE,
197201
path: 'loaders.0.loaders.0',
198202
},
199203
},

0 commit comments

Comments
 (0)