Skip to content

Commit

Permalink
Improve linter (#181)
Browse files Browse the repository at this point in the history
* fix empty tag for playwright

* linter

* upd husky script

* upd

* improve eslint config

* upd eslint config

* ignore decorator type import
  • Loading branch information
olexandr13 authored Sep 19, 2024
1 parent 226d7cf commit 92fc379
Show file tree
Hide file tree
Showing 9 changed files with 30 additions and 55 deletions.
38 changes: 2 additions & 36 deletions .eslintrc.js
Original file line number Diff line number Diff line change
@@ -1,46 +1,12 @@
module.exports = {
extends: 'airbnb-base',
extends: ['eslint:recommended', 'prettier'],
ignorePatterns: ['example/**/*.js', 'dist/'],
env: {
node: true,
es6: true,
},
parser: 'babel-eslint',
rules: {
'func-names': 0,
'no-use-before-define': 0,
'no-unused-vars': 0,
'no-underscore-dangle': 0,
'no-undef': 0,
'prefer-destructuring': 0,
'no-param-reassign': 0,
'max-len': 0,
camelcase: 0,
'no-shadow': 0,
'consistent-return': 0,
'no-console': 0,
'global-require': 0,
'class-methods-use-this': 0,
'no-plusplus': 0,
'no-return-assign': 0,
'prefer-rest-params': 0,
'no-useless-escape': 0,
'no-restricted-syntax': 0,
'no-unused-expressions': 0,
'guard-for-in': 0,
'no-multi-assign': 0,
'require-yield': 0,
'prefer-spread': 0,
'import/no-dynamic-require': 0,
'no-continue': 0,
'no-mixed-operators': 0,
'default-case': 0,
'import/no-extraneous-dependencies': 0,
'no-cond-assign': 0,
'import/no-unresolved': 0,
'no-await-in-loop': 0,
'arrow-body-style': 0,
'no-loop-func': 0,
'arrow-parens': 0,
'no-useless-concat': 0,
},
};
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@
"commander": "^8.2.0",
"debug": "^4.3.4",
"dotenv": "^10.0.0",
"eslint-config-prettier": "^9.1.0",
"glob": "^7.2.0",
"insert-line": "^1.1.0",
"object-hash": "^2.2.0",
Expand Down
3 changes: 2 additions & 1 deletion src/document.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
const fs = require('fs');
const hash = require('object-hash');
const Decorator = require('./decorator');
const util = require('./lib/utils');
// eslint-disable-next-line no-unused-vars
const Decorator = require('./decorator');

/**
*
Expand Down
6 changes: 3 additions & 3 deletions src/lib/frameworks/codeceptjs.js
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ module.exports = (ast, file = '', source = '', opts = {}) => {
if (path.isIdentifier({ name: 'Feature' })) {
if (!hasStringOrTemplateArgument(path.parent)) return;
currentSuite = getStringValue(path.parent);
currentScenario = null;
// currentScenario = null;
}

if (path.isIdentifier({ name: 'Before' })) {
Expand Down Expand Up @@ -155,15 +155,15 @@ module.exports = (ast, file = '', source = '', opts = {}) => {
if (!path.object.callee) return null;

if (path.object.callee.name === 'Data') {
test = tests[tests.length - 1];
const test = tests[tests.length - 1];
if (!test) return;
test.name = `${test.name.trim()} @${tagName}`;
return;
}

if (path.object.callee.name === 'Scenario') {
const scenarioName = getStringValue(path.object);
test = tests.filter(t => t.rawName === scenarioName)[0];
const test = tests.filter(t => t.rawName === scenarioName)[0];
if (!test) return;
test.name = `${test.name.trim()} @${tagName}`;
return;
Expand Down
1 change: 1 addition & 0 deletions src/lib/frameworks/newman.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ const debug = require('debug')('check-tests:newman');

// ast and file will be ignored
// if you need to expand the adapter with options, use opts = {}
// eslint-disable-next-line no-unused-vars
module.exports = (ast = '', file = '', source = '') => {
const collection = JSON.parse(source);
debug('Collection:\n', collection);
Expand Down
14 changes: 8 additions & 6 deletions src/lib/frameworks/playwright.js
Original file line number Diff line number Diff line change
Expand Up @@ -77,8 +77,10 @@ module.exports = (ast, file = '', source = '', opts = {}) => {
if (!path.parent || !path.parent.object) {
return;
}
/* prettier-ignore */
const name = path.parent?.object?.name || path.parent?.object?.callee?.object?.name || path.container?.object?.property?.name;
const name =
path.parent?.object?.name ||
path.parent?.object?.callee?.object?.name ||
path.container?.object?.property?.name;

if (['describe', 'it', 'context', 'test'].includes(name)) {
const line = getLineNumber(path);
Expand All @@ -95,8 +97,8 @@ module.exports = (ast, file = '', source = '', opts = {}) => {
if (!path.parent || !path.parent.object) {
return;
}
/* prettier-ignore */
const name = path.parent.object.name || path.parent.object.property.name || path.parent.object.callee.object.name;
const name =
path.parent.object.name || path.parent.object.property.name || path.parent.object.callee.object.name;

if (name === 'test' || name === 'it') {
// test or it
Expand Down Expand Up @@ -130,8 +132,8 @@ module.exports = (ast, file = '', source = '', opts = {}) => {
if (!path.parent || !path.parent.object) {
return;
}
/* prettier-ignore */
const name = path.parent.object.name || path.parent.object.property.name || path.parent.object.callee.object.name;
const name =
path.parent.object.name || path.parent.object.property.name || path.parent.object.callee.object.name;

if (name === 'test' || name === 'it') {
// test or it
Expand Down
1 change: 0 additions & 1 deletion src/reporter.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ const URL = process.env.TESTOMATIO_URL || 'https://app.testomat.io';
const isHttps = URL.startsWith('https');
const debug = require('debug')('testomatio:ids');
const { request } = isHttps ? require('https') : require('http');
const path = require('path');

class Reporter {
constructor(apiKey, framework) {
Expand Down
7 changes: 6 additions & 1 deletion src/updateIds/updateIds-newman.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,12 @@ const { parseTest } = require('./helpers');
* @param {*} currentRequestName request name without id
* @param {*} testId testId to add to request
*/
addIdToRequestAndUpdateCollection = function (collection, pathToRequestThrouthTheFolders, currentRequestName, testId) {
const addIdToRequestAndUpdateCollection = function (
collection,
pathToRequestThrouthTheFolders,
currentRequestName,
testId,
) {
function addIdToRequest(items, pathToRequestThrouthTheFolders) {
const currentFolder = pathToRequestThrouthTheFolders.shift();
for (const item of items) {
Expand Down
14 changes: 7 additions & 7 deletions src/updateIds/updateIds.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ const { parseTest, parseSuite, replaceSuiteTitle } = require('./helpers');
* @param {*} opts
* @returns
*/
function updateIdsCommon(testData, testomatioMap, workDir, opts = {}) {
function updateIdsCommon(testData, testomatioMap, workDir) {
const files = [];
let duplicateTests = 0;
let duplicateSuites = 0;
Expand All @@ -35,9 +35,9 @@ function updateIdsCommon(testData, testomatioMap, workDir, opts = {}) {

const currentSuiteId = parseSuite(suiteIndex);
if (
currentSuiteId
&& testomatioMap.suites[suiteIndex] !== `@S${currentSuiteId}`
&& testomatioMap.suites[suiteWithoutTags] !== `@S${currentSuiteId}`
currentSuiteId &&
testomatioMap.suites[suiteIndex] !== `@S${currentSuiteId}` &&
testomatioMap.suites[suiteWithoutTags] !== `@S${currentSuiteId}`
) {
debug(` Previous ID detected in suite '${suiteIndex}'`);
duplicateSuites++;
Expand Down Expand Up @@ -69,9 +69,9 @@ function updateIdsCommon(testData, testomatioMap, workDir, opts = {}) {

const currentTestId = parseTest(testIndex);
if (
currentTestId
&& testomatioMap.tests[testIndex] !== `@T${currentTestId}`
&& testomatioMap.tests[testWithoutTags] !== `@T${currentTestId}`
currentTestId &&
testomatioMap.tests[testIndex] !== `@T${currentTestId}` &&
testomatioMap.tests[testWithoutTags] !== `@T${currentTestId}`
) {
debug(`Previous ID detected in test '${testIndex}'`);
duplicateTests++;
Expand Down

0 comments on commit 92fc379

Please sign in to comment.