From 6f84539038c1c036db260fb06445f1d66b5eaced Mon Sep 17 00:00:00 2001 From: Christopher Pickering Date: Fri, 29 Jul 2022 07:37:21 -0500 Subject: [PATCH 1/6] fix(t027): fixed test and regression in T027 closes #141 --- src/djlint/rules.yaml | 10 ++-------- tests/test_linter/test_linter.py | 2 +- 2 files changed, 3 insertions(+), 9 deletions(-) diff --git a/src/djlint/rules.yaml b/src/djlint/rules.yaml index 420ec44..11ab245 100644 --- a/src/djlint/rules.yaml +++ b/src/djlint/rules.yaml @@ -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 -%} diff --git a/tests/test_linter/test_linter.py b/tests/test_linter/test_linter.py index f9f3081..7168b40 100644 --- a/tests/test_linter/test_linter.py +++ b/tests/test_linter/test_linter.py @@ -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 From b6b5410d1928ed8201991b9139f8dac479d3ee8a Mon Sep 17 00:00:00 2001 From: Christopher Pickering Date: Fri, 29 Jul 2022 09:55:33 -0500 Subject: [PATCH 2/6] chore(npm): improved npm install process to work on more systems Removed the node install script and just install directly with a node-script. --- bin/install.js | 21 --------------------- package.json | 2 +- 2 files changed, 1 insertion(+), 22 deletions(-) delete mode 100755 bin/install.js diff --git a/bin/install.js b/bin/install.js deleted file mode 100755 index 1908bd7..0000000 --- a/bin/install.js +++ /dev/null @@ -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); -} diff --git a/package.json b/package.json index bc1e9f7..58fb134 100644 --- a/package.json +++ b/package.json @@ -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" From 97363257ffedb77c11e0ff4c4cdfd141a4e4034e Mon Sep 17 00:00:00 2001 From: Christopher Pickering Date: Fri, 29 Jul 2022 09:57:53 -0500 Subject: [PATCH 3/6] test(npm test): updated npm test to removed old script --- .github/workflows/test.yml | 2 -- 1 file changed, 2 deletions(-) diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 35281a9..fe83f5b 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -71,8 +71,6 @@ 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 - name: test run lint From 181a730ce5fade9ffc2ed4a5fafa49ef43c11ab5 Mon Sep 17 00:00:00 2001 From: Christopher Pickering Date: Fri, 29 Jul 2022 10:22:14 -0500 Subject: [PATCH 4/6] added pip print to install --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index 58fb134..0dfcd49 100644 --- a/package.json +++ b/package.json @@ -37,7 +37,7 @@ }, "scripts": { "format": "prettier --config .prettierrc \"{bin,docs}/**/*.{ts,css,less,scss,js,json,md,yaml,html}\" --write", - "postinstall": "python3 -m pip install --upgrade djlint", + "postinstall": "python3 -m pip install --upgrade djlint && python3 -m pip list -v", "pre-commit": "lint-staged", "commit": "git add . && pre-commit run; npm run pre-commit && cz --no-verify", "test": "xo" From c6d0c1b549f049cda203629717781818fb31f0fa Mon Sep 17 00:00:00 2001 From: Christopher Pickering Date: Fri, 29 Jul 2022 10:32:53 -0500 Subject: [PATCH 5/6] remove script to call djlint directly --- .github/workflows/test.yml | 6 +- bin/index.js | 202 ------------------------------------- package.json | 2 +- 3 files changed, 4 insertions(+), 206 deletions(-) delete mode 100644 bin/index.js diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index fe83f5b..088c1c6 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -72,8 +72,8 @@ jobs: - name: install project run: npm --omit=dev install - name: test run help - run: node ./bin/index.js -h + run: djlint -h - name: test run lint - run: echo "
a
" | node ./bin/index.js + run: echo "
a
" | djlint - name: test run check - run: echo "
" | node ./bin/index.js --check + run: echo "
" | djlint --check diff --git a/bin/index.js b/bin/index.js deleted file mode 100644 index 0efe2ca..0000000 --- a/bin/index.js +++ /dev/null @@ -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