mirror of
https://github.com/Hopiu/djLint.git
synced 2026-05-14 08:13:09 +00:00
Merge pull request #313 from Riverside-Healthcare/dev
This commit is contained in:
commit
0d8a6b4a90
6 changed files with 7 additions and 238 deletions
8
.github/workflows/test.yml
vendored
8
.github/workflows/test.yml
vendored
|
|
@ -71,11 +71,9 @@ jobs:
|
|||
|
||||
- name: install project
|
||||
run: npm --omit=dev install
|
||||
- name: test post install
|
||||
run: node ./bin/install.js
|
||||
- name: test run help
|
||||
run: node ./bin/index.js -h
|
||||
run: djlint -h
|
||||
- name: test run lint
|
||||
run: echo "<div>a</div>" | node ./bin/index.js
|
||||
run: echo "<div>a</div>" | djlint -
|
||||
- name: test run check
|
||||
run: echo "<div>" | node ./bin/index.js --check
|
||||
run: echo "<div>" | djlint - --check
|
||||
|
|
|
|||
202
bin/index.js
202
bin/index.js
|
|
@ -1,202 +0,0 @@
|
|||
#!/usr/bin/env node
|
||||
|
||||
const process = require('process');
|
||||
const { PythonShell } = require('python-shell');
|
||||
|
||||
PythonShell.defaultOptions = {
|
||||
mode: 'text',
|
||||
pythonOptions: ['-u'],
|
||||
env: { PYCHARM_HOSTED: 1 }, // Force color
|
||||
};
|
||||
|
||||
function clean(output) {
|
||||
return output.replace(/python -m /g, '');
|
||||
}
|
||||
|
||||
const yargs = require('yargs');
|
||||
|
||||
const stdin = process.stdin;
|
||||
|
||||
function getStdin() {
|
||||
// https://github.com/sindresorhus/get-stdin/pull/19/files
|
||||
let returnValue = '';
|
||||
|
||||
return new Promise((resolve) => {
|
||||
if (stdin.isTTY) {
|
||||
resolve(returnValue);
|
||||
return;
|
||||
}
|
||||
|
||||
const timeout = setTimeout(() => {
|
||||
resolve(returnValue);
|
||||
}, 100);
|
||||
|
||||
stdin.unref();
|
||||
stdin.setEncoding('utf8');
|
||||
|
||||
stdin.on('readable', () => {
|
||||
clearTimeout(timeout);
|
||||
stdin.ref();
|
||||
|
||||
let chunk;
|
||||
|
||||
while ((chunk = stdin.read())) {
|
||||
returnValue += chunk;
|
||||
}
|
||||
});
|
||||
|
||||
stdin.on('end', () => {
|
||||
resolve(returnValue);
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
getStdin().then((string_) => {
|
||||
run(string_);
|
||||
});
|
||||
|
||||
function run(stdin) {
|
||||
const options = yargs
|
||||
.scriptName('djlint')
|
||||
.usage(
|
||||
`Usage: $0 [OPTIONS] SRC ...
|
||||
|
||||
djLint · lint and reformat HTML templates.`,
|
||||
)
|
||||
.option('e', {
|
||||
alias: 'extension',
|
||||
describe: 'File extension to check [default: html]',
|
||||
type: 'string',
|
||||
demandOption: false,
|
||||
})
|
||||
.option('h', {
|
||||
alias: 'help',
|
||||
describe: 'Show this message and exit.',
|
||||
type: 'boolean',
|
||||
demandOption: false,
|
||||
})
|
||||
.option('i', {
|
||||
alias: 'ignore',
|
||||
describe: 'Codes to ignore. ex: "H014,H017"',
|
||||
type: 'string',
|
||||
demandOption: false,
|
||||
})
|
||||
.option('reformat', {
|
||||
describe: 'Reformat the file(s).',
|
||||
type: 'boolean',
|
||||
demandOption: false,
|
||||
})
|
||||
.option('check', {
|
||||
describe: 'Check formatting on the file(s).',
|
||||
type: 'boolean',
|
||||
demandOption: false,
|
||||
})
|
||||
.option('indent', {
|
||||
describe: 'Indent spacing. [default: 4]',
|
||||
type: 'int',
|
||||
demandOption: false,
|
||||
})
|
||||
.option('quiet', {
|
||||
describe: 'Do not print diff when reformatting.',
|
||||
type: 'boolean',
|
||||
demandOption: false,
|
||||
})
|
||||
.option('warn', {
|
||||
describe: 'Return errors as warnings.',
|
||||
type: 'boolean',
|
||||
demandOption: false,
|
||||
})
|
||||
.option('profile', {
|
||||
describe:
|
||||
'Enable defaults by template language. ops: django, jinja, nunjucks, handlebars, golang, angular, html [default: html]',
|
||||
type: 'string',
|
||||
demandOption: false,
|
||||
})
|
||||
.option('require-pragma', {
|
||||
describe:
|
||||
"Only format or lint files that starts with a comment with the text 'djlint:on'",
|
||||
type: 'boolean',
|
||||
demandOption: false,
|
||||
})
|
||||
.option('lint', {
|
||||
describe: 'Lint for common issues. [default option]',
|
||||
type: 'boolean',
|
||||
demandOption: false,
|
||||
})
|
||||
.option('use-gitignore', {
|
||||
describe: 'Use .gitignore file to extend excludes.',
|
||||
type: 'boolean',
|
||||
demandOption: false,
|
||||
})
|
||||
.option('format-css', {
|
||||
describe: 'Also format contents of <style> tags.',
|
||||
type: 'boolean',
|
||||
demandOption: false,
|
||||
})
|
||||
.option('format-js', {
|
||||
describe: 'Also format contents of <script> tags.',
|
||||
type: 'boolean',
|
||||
demandOption: false,
|
||||
}).argv;
|
||||
|
||||
// Set flags
|
||||
const quiet = options.quiet ? '--quiet' : undefined;
|
||||
const help = options.h ? '--help' : undefined;
|
||||
const warn = options.warn ? '--warn' : undefined;
|
||||
const reformat = options.reformat ? '--reformat' : undefined;
|
||||
const check = options.check ? '--check' : undefined;
|
||||
const require_pragma = options['require-pragma']
|
||||
? '--require-pragma'
|
||||
: undefined;
|
||||
const lint = options.lint ? '--lint' : undefined;
|
||||
const use_gitignore = options['use-gitignore']
|
||||
? '--use-gitignore'
|
||||
: undefined;
|
||||
const format_css = options['format-css'] ? '--format-css' : undefined;
|
||||
const format_js = options['format-js'] ? '--format-js' : undefined;
|
||||
const has_stdin = stdin === '' ? options._[0] : '-';
|
||||
|
||||
// Set variables
|
||||
const indent = options.indent ? '--indent=' + options.indent : undefined;
|
||||
const profile = options.profile ? '--profile=' + options.profile : undefined;
|
||||
const ignore = options.ignore ? '--ignore=' + options.ignore : undefined;
|
||||
const extension = options.e ? '-e=' + options.extension : undefined;
|
||||
|
||||
const args = [
|
||||
has_stdin,
|
||||
warn,
|
||||
help,
|
||||
quiet,
|
||||
extension,
|
||||
reformat,
|
||||
check,
|
||||
require_pragma,
|
||||
lint,
|
||||
use_gitignore,
|
||||
indent,
|
||||
profile,
|
||||
ignore,
|
||||
format_css,
|
||||
format_js,
|
||||
].filter((x) => {
|
||||
return x !== undefined;
|
||||
});
|
||||
|
||||
const pyshell = new PythonShell('-m', { args: ['djlint', ...args] });
|
||||
|
||||
if (stdin !== '') {
|
||||
pyshell.send(stdin);
|
||||
}
|
||||
|
||||
pyshell.on('message', function (message) {
|
||||
console.log(clean(message));
|
||||
});
|
||||
|
||||
pyshell.on('stderr', function (message) {
|
||||
console.log(clean(message));
|
||||
});
|
||||
|
||||
pyshell.end(function (error, code) {
|
||||
process.exit(code);
|
||||
});
|
||||
}
|
||||
|
|
@ -1,21 +0,0 @@
|
|||
const { PythonShell } = require('python-shell');
|
||||
|
||||
PythonShell.defaultOptions = {};
|
||||
const options = {
|
||||
mode: 'text',
|
||||
args: ['pip', 'install', 'djlint'],
|
||||
pythonOptions: ['-u'],
|
||||
env: { PYCHARM_HOSTED: 1 },
|
||||
};
|
||||
|
||||
try {
|
||||
PythonShell.getVersionSync();
|
||||
|
||||
PythonShell.run('-m', options, function (error, results) {
|
||||
if (error) throw error;
|
||||
console.log(results.join('\n'));
|
||||
});
|
||||
} catch (e) {
|
||||
console.log(e.message);
|
||||
process.exit(1);
|
||||
}
|
||||
|
|
@ -37,7 +37,7 @@
|
|||
},
|
||||
"scripts": {
|
||||
"format": "prettier --config .prettierrc \"{bin,docs}/**/*.{ts,css,less,scss,js,json,md,yaml,html}\" --write",
|
||||
"postinstall": "node ./bin/install.js",
|
||||
"postinstall": "python3 -m pip install --upgrade djlint",
|
||||
"pre-commit": "lint-staged",
|
||||
"commit": "git add . && pre-commit run; npm run pre-commit && cz --no-verify",
|
||||
"test": "xo"
|
||||
|
|
|
|||
|
|
@ -210,15 +210,9 @@
|
|||
- "{{((?:(?!\"|}}).)*?(\")(?:(?!\\2|}}).)*?\\2(?:(?!\\2|}}).)*?)*\\2(?:(?!\\2|}}).)*?}}"
|
||||
|
||||
# for tags with a single quote
|
||||
# for double quotes
|
||||
- "{%((?:(?!\"|%}).)*?(\")(?:(?!\\2|%}).)*?)%}"
|
||||
# for single quotes
|
||||
- "{%((?:(?!'|%}).)*?(')(?:(?!\\2|%}).)*?)%}"
|
||||
- "{%((?:(?!'|\"|%}).)*?('|\")(?:(?!\\2|%}).)*?)%}"
|
||||
- "{{((?:(?!'|\"|}}).)*?('|\")(?:(?!\\2|}}).)*?)}}"
|
||||
|
||||
# for double quotes
|
||||
- "{{((?:(?!\"|}}).)*?(\")(?:(?!\\2|}}).)*?)}}"
|
||||
# for single quotes
|
||||
- "{{((?:(?!'|}}).)*?(')(?:(?!\\2|}}).)*?)}}"
|
||||
- rule:
|
||||
name: T028
|
||||
message: Consider using spaceless tags inside attribute values. {%- if/for -%}
|
||||
|
|
|
|||
|
|
@ -590,7 +590,7 @@ def test_T027(runner: CliRunner, tmp_file: TextIO) -> None:
|
|||
tmp_file.name,
|
||||
b'{% trans "Check box if you\'re interested in this location." %}',
|
||||
)
|
||||
result = runner.invoke(djlint, [tmp_file.name])
|
||||
result = runner.invoke(djlint, [tmp_file.name, "--profile", "django"])
|
||||
assert "T027" not in result.output
|
||||
|
||||
# test mixed quotes
|
||||
|
|
|
|||
Loading…
Reference in a new issue