-
Notifications
You must be signed in to change notification settings - Fork 8
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
Global configuration file #104
Comments
I like this. Personal default settings for quick scripts. We could follow the conventions of Unix desktop environments (GNOME, KDE) and put the files in the So the full filename could be (To be pedantic, the location of the config directory comes from the environment variable (There's a similar convention of using the |
I am not in support of the Unibeautify configuration file having an option pointing to an absolute path, such as in @muuvmuuv 's example #2: #104 (comment) Here's the discussion we had over in VSCode project: Unibeautify/vscode#55 (comment) I'd recommend using I think Cosmiconfig -- which Unibeautify uses -- already searches the home directory: https://github.com/davidtheclark/cosmiconfig#explorersearch |
Agreed. I think it would be a good idea to support user defaults, but the pathname should be implicit (always in a standard location) or given to the CLI as |
The standard path would be See https://github.com/davidtheclark/cosmiconfig#explorersearch and https://github.com/davidtheclark/cosmiconfig#stopdir However, this may only work if your code is within your home directory. Looks like it would not currently work because of the cosmiconfig("unibeautify", { stopDir: filePath }); @muuvmuuv As mentioned in #104 (comment) my recommendation is to use the already supported
My problem with allowing these global configuration files is they should really be stored within the project itself so they can be shared throughout your team. It means if I clone your repository, I am not able to reproduce the same results and therefore creates a confusing experience. At this time, I'm not confident I would even accept a Pull Request implementing this global configuration support by changing |
@Glavin001 I didn't mean to replace a projects config file, I totally agree to share configs within a project. I mean just for fast beautifications somewhere outside my projects. I often place files in
This would be the query, so only if 1. and 2. did not find anything, we would try to load |
I fully agree, but the point of the global file would be to serve defaults for one-off hacks (e.g. when you spend an hour writing a throwaway script - code formatting is still very useful in these situations). It could also serve as the default for temporary code in a text editor that isn't saved to any file (I often do this several times a day to work out some ideas). Similar to the way text editors have default settings for coding style but can change them per project.
It seems all of us are actually confusing two different approaches here.
It's true that traditionally config files have gone directly under the homedir, but |
Another way to put it: to inherit/extend a coding style should be a separate matter from the default coding style. The default style should only be used for files/projects that don't have any config file of their own. |
Agreed. I follow these practices, too, and would benefit.
So currently we can already use
This is possible now for VSCode with the merge of Unibeautify/vscode#57 and we just want this also to be available for Unibeautify CLI 🤔 . I am OK with a Unibeautify CLI solution which is not available in the Unibeautify core. I see Instead of changing or removing Something like: private configFile({
configFile,
filePath,
}: {
configFile?: string;
filePath?: string;
}) {
const configExplorer = cosmiconfig("unibeautify", { stopDir: filePath });
const loadConfigPromise = configFile
? configExplorer.load(configFile)
: configExplorer.search(filePath);
return loadConfigPromise
.then(result => (result ? result.config : null))
.catch(error => {
// ======== CHANGE BELOW HERE
const homeDir = require('os').homedir();
const defaultConfigExplorer = cosmiconfig("unibeautify", { stopDir: homeDir });
return configExplorer.load(homeDir);
})
.catch(error =>
Promise.reject(
new Error(`Could not load configuration file ${configFile}`)
)
);
} |
Good thinking. In light of this, I would suggest one of the following:
The right spelling ( |
The VS Code extension already got the option to pass a default config file, if no config file is provided in the project itself. We could do the same in two ways:
~/.unibeautifyrc.json
~/.unibeautifrc.json
file to set CLI options e.g.:The text was updated successfully, but these errors were encountered: