Skip to content
This repository has been archived by the owner on Mar 23, 2024. It is now read-only.

Add ability to declare acceptable values for the rules #895

Closed
markelog opened this issue Jan 9, 2015 · 16 comments
Closed

Add ability to declare acceptable values for the rules #895

markelog opened this issue Jan 9, 2015 · 16 comments

Comments

@markelog
Copy link
Member

markelog commented Jan 9, 2015

Now this responsibility falls on the configure method, but it would much easier if this method would be replaced by some declaration like:

values: [{
    type: "object",
    value: { 
        type: "string",
        value: "allExcept"
    }
}, {
    type: "boolean",
    value: true
}];

we couldn't fully dispose from the configure method, but it will simplify a lot of things

/cc @mdevils

Want to back this issue? Post a bounty on it! We accept bounties via Bountysource.

@qfox
Copy link
Member

qfox commented Jan 10, 2015

It can be replaced with a function({Conf} conf) with some conf.registerRuleValue inside.

Also one rule could handle several rules and values. And also one rule could have aliases (for modern configuration).

But fully declarative version (yours) will also be good.

@mdevils
Copy link
Member

mdevils commented Jan 10, 2015

As I can remember, @mikesherov wanted to do something about it.

@markelog
Copy link
Member Author

As I can remember, @mikesherov wanted to do something about it.

Yeah, i remember something like that, although no one responded when i repeatedly ask about this, hence the ticket

@mrjoelkemp
Copy link
Member

Looks good and manageable. Nice work, Oleg.

Who will implement the validation using this? I can help port some rules
once the validator is in master.

We just have to make sure no rule currently overrides this.values in its
configure. If none do, the validator can just check for the existence of
values on a rule and run the validator then configure, or just run
configure. Hence, the validator can be shipped quickly without being used.
On Jan 9, 2015 4:02 PM, "Oleg Gaidarenko" notifications@github.com wrote:

Now this responsibility falls on the configure method, but it would much
easier if this method would be replaced by some declaration like:

values: [{
type: "object",
value: {
type: "string",
value: "allExcept"
}
}, {
type: "boolean",
value: true
}];

we couldn't fully dispose from the configure method, but it will simplify
a lot of things

/cc @mdevils https://github.com/mdevils


Reply to this email directly or view it on GitHub
#895.

@markelog
Copy link
Member Author

Who will implement the validation using this?

Whoever is capable and have time to do this :-), after 1.10 my next item is jquery tasks, there is a lot them accumulated out there.

We just have to make sure no rule currently overrides this.values

configure method usually set only private properties (style which @mdevils set long time ago, nice going btw :-) i.e. with "_" prefix, so we should be good there.

Hence, the validator can be shipped quickly without being used.

That is my thought exactly.

@mikesherov
Copy link
Contributor

I think I still have an open issue about this somewhere...

My thoughts were to make rule values declarative rather than having functions. This would also make documentation auto generate able.

@qfox
Copy link
Member

qfox commented Feb 5, 2015

We can try to use here https://github.com/molnarg/js-schema/ or analogue. But it's 24Kb. Probably we can find more lighten solution.

@hzoo
Copy link
Member

hzoo commented Mar 20, 2015

@hzoo
Copy link
Member

hzoo commented Mar 23, 2015

Some stuff on a declarative format:

values: [
    // true,
    // number,
    // string
    // one of the strings in an array
    // object with properties 'beforeOpeningRoundBrace' and 'beforeOpeningCurlyBrace' which are both true
];

// markelog's original one
values: [{
    type: "boolean",
    value: true
}, {
    type: "number" // maybe no value?
}, {
    type: "string"
}, {
    type: "string",
    value: ['a', 'b', 'c']
}, {
    type: "object",
    value: [ // not sure how this would work
        { 
            type: "string",
            value: "beforeOpeningCurlyBrace"
        },
        { 
            type: "string",
            value: "beforeOpeningRoundBrace"
        },
    ]
}, ];

// use constructor functions? (js-schema)
values: [
    true,
    Number,
    ['a', 'b', 'c'],
    {
        beforeOpeningCurlyBrace: [String] 
        beforeOpeningRoundBrace: [String] 
    }
];

// react type (namespaces to represent things)
values: [
    Types.true,
    Types.number,
    Types.oneOf(['a', 'b', 'c']),
    Types.object({
        beforeOpeningCurlyBrace: Types.arrayOf(Types.String)
        beforeOpeningRoundBrace: Types.arrayOf(Types.String)
    })
];

I do like the 2nd one if something like that is possible?

@qfox
Copy link
Member

qfox commented Mar 30, 2015

Nice stuff. Thanks! ;-)

About 2nd one: https://github.com/molnarg/js-schema/ — 25Kb, can be used in browser. Is it fine for us?

@hzoo
Copy link
Member

hzoo commented Mar 31, 2015

Looks like ESLint has an issue about notifying on config options using a declarative approach too! There's also https://github.com/mafintosh/is-my-json-valid and https://github.com/hapijs/joi.

@hzoo
Copy link
Member

hzoo commented May 19, 2015

Do we know if we're going to use another tool to validate or make our own?

@mrjoelkemp
Copy link
Member

Looking to use one of the suggested tools. The proposed schema would change
to fit the tool. Experimenting with the options for now.
On May 19, 2015 8:14 AM, "Henry Zhu" notifications@github.com wrote:

Do we know if we're going to use another tool to validate or make our own?


Reply to this email directly or view it on GitHub
#895 (comment).

@markelog
Copy link
Member Author

What options do we have on the table?

@mrjoelkemp
Copy link
Member

I've been looking at the ones suggested in this thread mostly. @hzoo's suggestion of https://github.com/mafintosh/is-my-json-valid feels like the best one so far. I'm in the middle of a prototype with it, so no guarantees that it'll work just yet.

@hzoo
Copy link
Member

hzoo commented May 19, 2015

Yeah that's the one ESLint is planning on using as well - eslint/eslint#2179

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

6 participants