Skip to content

Commit

Permalink
feat(eslint-plugin) improve schema extension technique
Browse files Browse the repository at this point in the history
  • Loading branch information
scottohara committed Mar 28, 2019
1 parent 26c51e3 commit d83bc8e
Showing 1 changed file with 11 additions and 8 deletions.
19 changes: 11 additions & 8 deletions packages/eslint-plugin/src/rules/no-magic-numbers.ts
Expand Up @@ -11,13 +11,7 @@ import { JSONSchema4 } from 'json-schema';
type Options = util.InferOptionsTypeFromRule<typeof baseRule>;
type MessageIds = util.InferMessageIdsTypeFromRule<typeof baseRule>;

// Extend base schema with additional property to ignore TS numeric literal types
const properties = {
...(baseRule.meta.schema as JSONSchema4[])[0].properties,
ignoreNumericLiteralTypes: {
type: 'boolean',
},
};
const baseRuleSchema = (baseRule.meta.schema as JSONSchema4[])[0];

export default util.createRule<Options, MessageIds>({
name: 'no-magic-numbers',
Expand All @@ -28,7 +22,16 @@ export default util.createRule<Options, MessageIds>({
category: 'Best Practices',
recommended: false,
},
schema: { ...baseRule.meta.schema, ...properties },
// Extend base schema with additional property to ignore TS numeric literal types
schema: [{
...baseRuleSchema,
properties: {
...baseRuleSchema.properties,
ignoreNumericLiteralTypes: {
type: 'boolean',
},
},
}],
messages: baseRule.meta.messages,
},
defaultOptions: [
Expand Down

0 comments on commit d83bc8e

Please sign in to comment.