Closes #35. Add more options for Python PEP8 beautifying.
Options: - max line length - indent size - ignore (errors) Also fixed typo causing very important bug, such that languages were not loaded correctly and options were missing.
This commit is contained in:
parent
f7c7fc7614
commit
65ff7f9f7a
|
@ -30,3 +30,8 @@
|
||||||
indent_char: " "
|
indent_char: " "
|
||||||
indent_level: 0
|
indent_level: 0
|
||||||
indent_with_tabs: false
|
indent_with_tabs: false
|
||||||
|
python:
|
||||||
|
indent_size: 4
|
||||||
|
#max_line_length: 79
|
||||||
|
#ignore:
|
||||||
|
# - "E24"
|
||||||
|
|
|
@ -12,7 +12,7 @@ var strip = require('strip-json-comments');
|
||||||
var yaml = require('js-yaml');
|
var yaml = require('js-yaml');
|
||||||
// Language options
|
// Language options
|
||||||
var beautifier = require('./language-options');
|
var beautifier = require('./language-options');
|
||||||
var languages = beautifier.langauges;
|
var languages = beautifier.languages;
|
||||||
var defaultLanguageOptions = beautifier.defaultLanguageOptions;
|
var defaultLanguageOptions = beautifier.defaultLanguageOptions;
|
||||||
|
|
||||||
// TODO: Copied from jsbeautify, please update it from time to time
|
// TODO: Copied from jsbeautify, please update it from time to time
|
||||||
|
@ -156,21 +156,21 @@ function findConfig(config, file) {
|
||||||
function getConfigOptionsFromSettings(langs) {
|
function getConfigOptionsFromSettings(langs) {
|
||||||
var config = atom.config.getSettings()['atom-beautify'];
|
var config = atom.config.getSettings()['atom-beautify'];
|
||||||
var options = {};
|
var options = {};
|
||||||
// console.log(langs, config);
|
console.log(langs, config);
|
||||||
|
|
||||||
// Iterate over keys of the settings
|
// Iterate over keys of the settings
|
||||||
_.every(_.keys(config), function (k) {
|
_.every(_.keys(config), function (k) {
|
||||||
// Check if keys start with a language
|
// Check if keys start with a language
|
||||||
var p = k.split('_')[0];
|
var p = k.split('_')[0];
|
||||||
var idx = _.indexOf(langs, p);
|
var idx = _.indexOf(langs, p);
|
||||||
// console.log(k, p, idx);
|
console.log(k, p, idx);
|
||||||
if (idx >= 0) {
|
if (idx >= 0) {
|
||||||
// Remove the language prefix and nest in options
|
// Remove the language prefix and nest in options
|
||||||
var lang = langs[idx];
|
var lang = langs[idx];
|
||||||
var opt = k.replace(new RegExp('^' + lang + '_'), '');
|
var opt = k.replace(new RegExp('^' + lang + '_'), '');
|
||||||
options[lang] = options[lang] || {};
|
options[lang] = options[lang] || {};
|
||||||
options[lang][opt] = config[k];
|
options[lang][opt] = config[k];
|
||||||
// console.log(lang, opt);
|
console.log(lang, opt);
|
||||||
}
|
}
|
||||||
return true;
|
return true;
|
||||||
});
|
});
|
||||||
|
|
|
@ -8,12 +8,15 @@ var cliBeautify = require('./cli-beautify');
|
||||||
|
|
||||||
function getCmd(inputPath, outputPath, options) {
|
function getCmd(inputPath, outputPath, options) {
|
||||||
var path = options.autopep8_path; // jshint ignore: line
|
var path = options.autopep8_path; // jshint ignore: line
|
||||||
|
var optionsStr = '--max-line-length ' + options.max_line_length + // jshint ignore: line
|
||||||
|
' --indent-size ' + options.indent_size // jshint ignore: line
|
||||||
|
+ ' --ignore ' + options.ignore.join(','); // jshint ignore: line
|
||||||
if (path) {
|
if (path) {
|
||||||
// Use absolute path
|
// Use absolute path
|
||||||
return 'python "' + path + '" "' + inputPath + '"';
|
return 'python "' + path + '" "' + inputPath + '" ' + optionsStr;
|
||||||
} else {
|
} else {
|
||||||
// Use command available in $PATH
|
// Use command available in $PATH
|
||||||
return 'autopep8 "' + inputPath + '"';
|
return 'autopep8 "' + inputPath + '" ' + optionsStr;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
var isStdout = true;
|
var isStdout = true;
|
||||||
|
|
|
@ -57,6 +57,9 @@ module.exports = {
|
||||||
php_beautifier_path: '',
|
php_beautifier_path: '',
|
||||||
// Python
|
// Python
|
||||||
python_autopep8_path: '',
|
python_autopep8_path: '',
|
||||||
|
python_max_line_length: 79,
|
||||||
|
python_indent_size: 4,
|
||||||
|
python_ignore: ['E24'],
|
||||||
// Ruby
|
// Ruby
|
||||||
ruby_rbeautify_path: ''
|
ruby_rbeautify_path: ''
|
||||||
/* jshint ignore: end */
|
/* jshint ignore: end */
|
||||||
|
@ -156,4 +159,4 @@ module.exports = {
|
||||||
|
|
||||||
return options;
|
return options;
|
||||||
}
|
}
|
||||||
}
|
};
|
||||||
|
|
Loading…
Reference in New Issue