Skip to content
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

Fix quality gate #4272

Merged
merged 5 commits into from
Oct 16, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion packages/bridge/tests/tools/request.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ export function request(server: http.Server, path: string, method: string, data:
host: '127.0.0.1',
path,
method,
port: (<AddressInfo>server.address()).port,
port: (server.address() as AddressInfo).port,
headers: {
'Content-Type': 'application/json',
},
Expand Down
2 changes: 1 addition & 1 deletion packages/css/tests/tools/tester/tester.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ export type InvalidAssertion = {
class StylelintRuleTester {
private readonly config: stylelint.Config;

constructor(rule: { ruleName: string; rule: stylelint.Rule<any, any> }) {
constructor(rule: { ruleName: string; rule: stylelint.Rule }) {
stylelint.rules[rule.ruleName] = rule.rule;
this.config = { rules: { [rule.ruleName]: true } };
}
Expand Down
1 change: 0 additions & 1 deletion packages/jsts/src/rules/helpers/ast.ts
Original file line number Diff line number Diff line change
Expand Up @@ -412,7 +412,6 @@ function resolveIdentifiersAcc(
}
}

// TODO Drop this function and replace it with `getProperty`
export function getObjectExpressionProperty(
node: estree.Node | undefined | null,
propertyKey: string,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -61,20 +61,22 @@ export const rule: Rule.RuleModule = {
return;
}
const maybeMeta = getObjectExpressionProperty(node, 'meta');
if (maybeMeta) {
const maybeSchema = getObjectExpressionProperty(maybeMeta.value, 'schema');
if (maybeSchema && maybeSchema.value.type === 'ArrayExpression') {
const schema = maybeSchema.value;
for (const element of schema.elements) {
const maybeEnum = getObjectExpressionProperty(element, 'enum');
if (maybeEnum) {
isSecondaryLocationEnabled =
maybeEnum.value.type === 'ArrayExpression' &&
maybeEnum.value.elements.length === 1 &&
maybeEnum.value.elements[0].type === 'Identifier' &&
maybeEnum.value.elements[0].name === 'SONAR_RUNTIME';
}
}
if (!maybeMeta) {
return;
}
const maybeSchema = getObjectExpressionProperty(maybeMeta.value, 'schema');
if (maybeSchema?.value.type !== 'ArrayExpression') {
return;
}
const schema = maybeSchema.value;
for (const element of schema.elements) {
const maybeEnum = getObjectExpressionProperty(element, 'enum');
if (maybeEnum) {
isSecondaryLocationEnabled =
maybeEnum.value.type === 'ArrayExpression' &&
maybeEnum.value.elements.length === 1 &&
maybeEnum.value.elements[0].type === 'Identifier' &&
maybeEnum.value.elements[0].name === 'SONAR_RUNTIME';
}
}
},
Expand Down
2 changes: 1 addition & 1 deletion packages/jsts/tests/tools/testers/comment-based/checker.ts
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ const ruleTester = new RuleTester({ parser: __filename });
export function check(ruleId: string, ruleModule: Rule.RuleModule, ruleDir: string) {
const fixtures = [];
for (const file of fs.readdirSync(ruleDir)) {
if (file.match(/\.fixture\.(js|ts|jsx|tsx|vue)$/)) {
if (/\.fixture\.(js|ts|jsx|tsx|vue)$/.exec(file)) {
const fixture = path.join(ruleDir, file);
fixtures.push(fixture);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ export function isNonCompliantLine(comment: string) {
}

export function extractLineIssues(file: FileIssues, comment: Comment) {
const matcher = comment.value.match(NON_COMPLIANT_PATTERN);
const matcher = NON_COMPLIANT_PATTERN.exec(comment.value);
if (matcher === null) {
throw new Error(`Invalid comment format at line ${comment.line}: ${comment.value}`);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,10 +51,6 @@ export abstract class Location {

export class PrimaryLocation extends Location {
readonly secondaryLocations: SecondaryLocation[] = [];

constructor(range: Range) {
super(range);
}
}

export class SecondaryLocation extends Location {
Expand All @@ -79,7 +75,7 @@ export function extractLocations(file: FileIssues, comment: Comment) {
let offset = 0;
let matcher: RegExpMatchArray | null;
LOCATION_PATTERN.lastIndex = 0;
while ((matcher = toBeMatched.match(LOCATION_PATTERN)) !== null) {
while ((matcher = LOCATION_PATTERN.exec(toBeMatched)) !== null) {
locations.push(
matcherToLocation(line, column, commentContent.indexOf(matcher[1], offset) + 1, matcher),
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ export function isQuickfixLine(comment: string) {

export function extractQuickFixes(quickfixes: Map<string, QuickFix>, comment: Comment) {
if (QUICKFIX_DESCRIPTION_PATTERN.test(comment.value)) {
const matches = comment.value.match(QUICKFIX_DESCRIPTION_PATTERN);
const matches = QUICKFIX_DESCRIPTION_PATTERN.exec(comment.value);
const { quickfixId, message } = matches.groups;
const quickfix = quickfixes.get(quickfixId);
if (!quickfix) {
Expand All @@ -87,7 +87,7 @@ export function extractQuickFixes(quickfixes: Map<string, QuickFix>, comment: Co
}
quickfix.description = message;
} else if (QUICKFIX_CHANGE_PATTERN.test(comment.value)) {
const matches = comment.value.match(QUICKFIX_CHANGE_PATTERN);
const matches = QUICKFIX_CHANGE_PATTERN.exec(comment.value);
const {
quickfixId,
type,
Expand Down
2 changes: 1 addition & 1 deletion packages/jsts/tests/tools/testers/typescript/tester.ts
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ class TypeScriptRuleTester extends RuleTester {
super({
env,
parser,
parserOptions: parserOptions,
parserOptions,
});
}

Expand Down
18 changes: 17 additions & 1 deletion packages/shared/tests/helpers/debug.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
* along with this program; if not, write to the Free Software Foundation,
* Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*/
import { debug } from '../../src/helpers';
import { debug, info, warn } from '../../src/helpers';

describe('debug', () => {
it('should log with a `DEBUG` prefix', () => {
Expand All @@ -26,3 +26,19 @@ describe('debug', () => {
expect(console.log).toHaveBeenCalledWith(`DEBUG hello, world!`);
});
});

describe('warn', () => {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

thanks! ;-)

it('should log with a `WARN` prefix', () => {
console.log = jest.fn();
warn('hello, world!');
expect(console.log).toHaveBeenCalledWith(`WARN hello, world!`);
});
});

describe('info', () => {
it('should log with no prefix', () => {
console.log = jest.fn();
info('hello, world!');
expect(console.log).toHaveBeenCalledWith(`hello, world!`);
});
});
1 change: 1 addition & 0 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,7 @@
<sonar.javascript.lcov.reportPaths>coverage/lcov.info</sonar.javascript.lcov.reportPaths>
<sonar.typescript.tsconfigPath>${project.basedir}/packages/tsconfig.app.json,${project.basedir}/packages/tsconfig.test.json</sonar.typescript.tsconfigPath>
<sonar.cpd.exclusions>sonar-plugin/javascript-checks/src/main/resources/**/*.html</sonar.cpd.exclusions>
<sonar.coverage.exclusions>packages/bridge/src/worker.js</sonar.coverage.exclusions>
</properties>

<dependencyManagement>
Expand Down