Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Throw an error if config.storeName isn't a String #948

Open
wants to merge 7 commits into
base: master
Choose a base branch
from

Conversation

himanshu199728
Copy link

@himanshu199728 himanshu199728 commented Apr 18, 2020

Fixes #947

Copy link
Member

@tofumatt tofumatt left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is a neat idea, but it looks like your code is failing the lint checks (and from the looks of it will fail the tests).

Would you be willing to write a test case for this new code path? If you could do that and fix the other issues I mentioned, I think we could add this, thanks! 😄

return this._config[options];
} else {
return this._config;
} catch (err) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We shouldn't catch any error here; instead this should throw as it did previously.

if (i === 'storeName' && typeof options[i] !== 'string') {
options[i] = options[i].replace(/\W/g, '_');
} else {
return new Error('storeName must be a string');
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is a helpful touch, and I guess it isn't a breaking change since .replace on anything that isn't a String would fail anyway (since it isn't a function).

if (i === 'version' && typeof options[i] !== 'number') {
return new Error('Database version must be a number.');
for (let i in options) {
if (i === 'storeName' && typeof options[i] !== 'string') {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Reading this code it seems like this if check will fail (calling the else block below) for any option key that isn't storeName. You'll want to nest the check for (typeof options[i] !== 'string') inside this if statement or this will break other things.

for (let i in options) {
if (i === 'storeName') {
options[i] = options[i].replace(/\W/g, '_');
try {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think this try/catch block here is helpful to add, as it will prevent unexpected errors from throwing.

@@ -314,7 +322,7 @@ class LocalForage {
}

function initDriver(supportedDrivers) {
return function() {
return function () {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not sure why these code changes were made, but they're failing the linter; could you please revert these style/whitespace changes?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Got this due to correcting the indentation by some extension. I'll revert it back.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think test cases in the test folder needed to be more organized in categories for manging.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done with the changes and also added a test case in test/test.config.js regarding this issue fixing test. Can you check it again

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I didn't get any update from you, sir.

@tofumatt tofumatt changed the title Check fix of storeName Throw an error if config.storeName isn't a String #947 Apr 19, 2020
@tofumatt tofumatt changed the title Throw an error if config.storeName isn't a String #947 Throw an error if config.storeName isn't a String Apr 19, 2020
Copy link
Member

@tofumatt tofumatt left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is looking better; just a few tweaks to make and it should be good to merge. Thanks! 🙂

package.json Outdated
@@ -69,6 +69,7 @@
"url": "http://github.com/localForage/localForage/issues"
},
"dependencies": {
"jslint": "^0.12.1",
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This should be in devDependencies, not dependencies, as you don't need jslint to run the repo.

That said: this shouldn't need to be here at all. If we're using a linter it should be eslint, but we aren't using a linter (or, specifically, jslint) anywhere in the codebase or this PR. Could you remove this line please?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ok

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sorry, I forget that this type of dependency came under dev dependencies.

@@ -269,4 +269,16 @@ describe('Config API', function() {
expect(configResult.toString()).to.be(error);
done();
});

it('should throw error on config.storeName not string', function(done) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just a wording suggestion here to clean up the test:

Suggested change
it('should throw error on config.storeName not string', function(done) {
it('should throw error if config.storeName is not a string', function() {

(You also don't need to use done() here since this isn't an asynchronous test.)

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ok. Got it

@@ -269,4 +269,16 @@ describe('Config API', function() {
expect(configResult.toString()).to.be(error);
done();
});

it('should throw error on config.storeName not string', function(done) {
let configResult = localforage.config({
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
let configResult = localforage.config({
const configResult = localforage.config({

test/test.config.js Outdated Show resolved Hide resolved
package.json Outdated
@@ -23,6 +23,7 @@
"test": "node -e \"require('grunt').cli()\" null test"
},
"devDependencies": {
"jslint": "^0.12.1",
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Where is the code using jslint? I mentioned tooling like this belongs in devDependencies if used, but I don't see it being used anywhere in this PR so I think it's best to remove this.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ok

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done. I think now it good to go.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is it now ready to merge??

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please be patient; this is an open-source project and we don't always have the time to respond to PRs right away. I do check my issue queues/notifications but I can't get to things right away 🙂

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ok. No worry.

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

Successfully merging this pull request may close these issues.

Throw an error if config.storeName isn't a String
2 participants