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

File naming conventions #30

Open
muhammadnasr opened this issue Sep 22, 2014 · 8 comments
Open

File naming conventions #30

muhammadnasr opened this issue Sep 22, 2014 · 8 comments

Comments

@muhammadnasr
Copy link

Thanks for the great guide.

I wonder what about File naming conventions for js files, files can be modules or class

For example how class file for CustomerInvoice class be named?
Camel case or snake case?

Thanks.

@jonniedarko
Copy link

I like to use CustomerInvoice.class.js for a class only and CustomerInvoice.module.js for modules

@spalger
Copy link

spalger commented Nov 5, 2014

We currently follow a lower_snake_case naming convention, but many of the core contributors agree that we should have adopted a naming scheme that matches the expected output of that module. In that scenario, the require statement would match up with the variable it was assigned to.

// FooBarClass.js
module.exports = function FooBarClass() {
}
// someMapFunction.js
module.exports = function someMapFunction(item, i, list) {
}
// someContainerModule.js
module.exports = {
  Class1: require('./Class1')
};
// variables should match the filename
var FooBarClass = require('./FooBarClass');
var someMapFunction = require('./someMapFunction');
var Class1 = require('./someContainerModule').Class1;

@kentcdodds
Copy link
Contributor

I like that. It seems to make sense and makes it easier to identify where a
dependency came from.

  • Kent C. Dodds
    Sent from my mobile device, please forgive any errors or brevity. (I may
    have used speech to text...)
    On Nov 5, 2014 7:43 AM, "Spencer" [email protected] wrote:

We currently follow a snake-case naming convention, but all of the
core-contributes agree that we should have adopted a naming scheme that
matches the expected output of that module. In that scenario, the require
statement would match up with the variable it was assigned to.

// FooBarClass.js
module.exports = function FooBarClass() {
}

// someMapFunction.js
module.exports = function someMapFunction(item, i, list) {
}

// someContainerModule.js
module.exports = {
Class1: require('./Class1')
};

// variables should match the filenamevar FooBarClass = require('./FooBarClass');var someMapFunction = require('./someMapFunction');var someContainerModule = require('./someContainerModule');


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

@avishaan
Copy link

avishaan commented Nov 5, 2014

I don't like putting .class and .module especially because referring to classes in javascript is a bad habit to begin with.

Naming scheme to match expected output like @spenceralger said makes the most sense.

@Adhiii
Copy link

Adhiii commented Apr 12, 2017

I saved nodejs file as "dynamicrouting_with_restriction".
But while executing in commandprompt It displays cannotfind module...can anyone solve this issue?

@bronson
Copy link

bronson commented Sep 28, 2017

There appear to be two common styles: using the same case as the default identifier in the file (Promise.js, setInterval.js), and dash-separated (promise.js, set-interval.js).

Personally I favor dash separated to avoid accidental case sensitivity.

  • MSExchange.js   ms-exchange.js
  • MSexChange.js   m-sex-change.js )

(Any time you have filenames differing only by case, Mac users are going to complain.)

Since there may never be consensus here, it might be worth closing this issue and opening one on https://github.com/standard/standard

@whyDontI
Copy link

Inspired from Angular's file naming convention, I name my files as,

user.service.js
user.model.js
user.route.js
user.validator.js

@carlosmoliv
Copy link

dynamicrouting_with_restriction

Inspired from Angular's file naming convention, I name my files as,

user.service.js
user.model.js
user.route.js
user.validator.js

Hey, Do you know if naming the files in the singular is the best approach?

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

No branches or pull requests

11 participants