digitalbazaar / eslint-config-digitalbazaar

BSD 3-Clause "New" or "Revised" License
2 stars 1 forks source link

Add rule for dot-notation. #52

Closed mattcollier closed 3 years ago

mattcollier commented 3 years ago

Addresses: https://github.com/digitalbazaar/eslint-config-digitalbazaar/issues/46

// OK
const foo = {};
foo.bar = 1;
// this is common when dealing with bedrock configs and this does **not** produce an error
foo['some-baz'] = 8;

// error
foo['bar'] = 2;

https://eslint.org/docs/rules/dot-notation

aljones15 commented 3 years ago

@mattcollier could you add a test for this here: https://github.com/digitalbazaar/eslint-config-digitalbazaar/blob/main/test/index.js

Also, the eslint docs suggest that the foo[some-baz] rule requires a RegExp:

/*eslint camelcase: "error"*/
/*eslint dot-notation: ["error", { "allowPattern": "^[a-z]+(_[a-z]+)+$" }]*/

var data = {};
data.foo_bar = 42;

var data = {};
data["fooBar"] = 42;

var data = {};
data["foo_bar"] = 42; // no warning
mattcollier commented 3 years ago

@aljones15 you have presented some conflicting information here above. some-baz does not require a special regex where some_baz (underscore) does. I don't think our usage of foo['some_baz'] is common enough to warrant a global exception. I think these cases can be handled by eslint-disable-next-line as needed.

I probably won't be adding test for this, would someone else like to take over?

aljones15 commented 3 years ago

@aljones15 you have presented some conflicting information here above. some-baz does not require a special regex where some_baz (underscore) does. I don't think our usage of foo['some_baz'] is common enough to warrant a global exception. I think these cases can be handled by eslint-disable-next-line as needed.

I probably won't be adding test for this, would someone else like to take over?

My apologies about the mistake. I guess I'll add a test for your cases now. Do we want to error on: data['foo_bar']? I believe I have seen that as a property in a JSON object before.

p.s. thank you for the work though.

aljones15 commented 3 years ago

ok so the remaining issue with this P.R. is we are allowing kebab-case, but do we want to allow snake_case? https://en.wikipedia.org/wiki/Snake_case?