I am running clang-tidy for my project. Here are the relevant naming options from my .clang-tidy file:
- key: readability-identifier-naming.ClassMemberCase # e.g., int myClassMember_
value: camelBack
- key: readability-identifier-naming.ClassMemberSuffix # e.g., int myClassMember_
value: _
- key: readability-identifier-naming.GlobalConstantCase # e.g., int MyGlobalConstant (please don't make globals)
value: CamelCase
- key: readability-identifier-naming.IgnoreMainLikeFunctions # Doesn't apply clang checks to main() args
value: 1
- key: readability-identifier-naming.MacroDefinitionCase # e.g., #define MY_MACRO="PleaseDon'tUseMacrosAnywhere"
value: UPPER_CASE
- key: readability-identifier-naming.MacroDefinitionIgnoredRegexp
value: '^[A-Z]+(_[A-Z]+)*_$'
- key: readability-identifier-naming.MemberCase # e.g., int myMember_ = 42;
value: CamelCase
- key: readability-identifier-naming.MemberSuffix # e.g., int myMember_ = 42;
value: _
- key: readability-identifier-naming.ParameterCase # e.g., void MyFunction(int parameter, int anotherParam);
value: camelBack
- key: readability-identifier-naming.StaticConstantCase # e.g., static const std::string s_myStaticConstant = "I hope this works!"
value: camelBack
- key: readability-identifier-naming.StaticConstantPrefix # e.g., static const std::string s_myStaticConstant = "I hope this works!"
value: s_
- key: readability-identifier-naming.StaticVariableCase # e.g., static std::string s_myStaticVar = "I hope this works!"
value: camelBack
- key: readability-identifier-naming.StaticVariablePrefix # e.g., static std::string s_myStaticVar = "I hope this works!"
value: s_
- key: readability-identifier-naming.StructCase # e.g., struct MyStruct { ... };
value: CamelCase
- key: readability-identifier-naming.VariableCase # e.g., int myVariable = 10;
value: camelBack
Unfortunately, clang tidy turns my static class member variables into sMyVariable_ instead of s_myVariable_. It seems as if the options for class members are overriding the options for static variables:
warning: invalid case style for class member 's_myVariable_' [readability-identifier-naming]
int MyClass::s_myVariable_ = 1;
Is there any way to have the static naming rules prioritized over the member naming rules? Thanks!
Example code:
class MyClass{
static int s_myVariable_; // Clang-tidy doesn't like this
};
I had a hard time finding this in the documentation as well. It appears that static member variable readability-identifier-naming styles are defined with ClassMemberCase, ClassMemberPrefix, and ClassMemberSuffix.
For your desired formatting
class MyClass{
static int s_myVariable_; // Clang-tidy doesn't like this
};
the CheckOptions field of the .clang-tidy file would have the follwing key/values:
- { key: readability-identifier-naming.ClassMemberPrefix, value: s_ }
- { key: readability-identifier-naming.ClassMemberCase, value: camelBack }
- { key: readability-identifier-naming.ClassMemberSuffix, value: _ }
Related
I'm trying to use clang-tidy on Windows from MSVC (Clang 13.0.1 for MSVC 2022 amd). The renaming is applied to the header file, but not fully to the cpp file.
.clang-tidy
Checks: '-*,readability-identifier-naming'
CheckOptions:
- { key: readability-identifier-naming.ClassCase, value: lower_case }
- { key: readability-identifier-naming.ClassMemberCase, value: lower_case }
- { key: readability-identifier-naming.ClassMethodCase, value: lower_case }
- { key: readability-identifier-naming.FunctionCase, value: lower_case }
- { key: readability-identifier-naming.ParameterCase, value: lower_case }
- { key: readability-identifier-naming.VariableCase, value: lower_case }
Header:
#pragma once
class NeedsTidying
{
public:
int addFunc(int argOne, int argTwo);
int subFunc(int argOne, int argTwo) {
return argOne - argTwo;
}
};
cpp:
#include "tidy.hpp"
int NeedsTidying::addFunc(int argOne, int argTwo) {
return argOne + argTwo;
}
clang-tidy arguments: clang-tidy --fix-errors -p build\compile_commands.json path_to_code*
clang-tidy gets applied to the header file as I expect, but the cpp file doesn't apply the class name or method renames as I expect:
int NeedsTidying::addFunc(int arg_one, int arg_two) {
return arg_one + arg_two;
}
This error occasionally occurs on "cdk watch" and disappears when I destroy and redeploy the stack. All the global and per lambda variables are strings for sure. The table name is not declared explicitly but generated from the id..(maybe this is the cause of the issue?)
export class MyStack extends Stack {
constructor(app: App, id: string, props: MyStackProps) {
super(app, id);
const isProd = props.deploymentEnv;
const stackName = Stack.of(this).stackName;
const PRIMARY_KEY = 'reportId';
const dynamoTable = new Table(this, `MyTable-${stackName}`, {
partitionKey: {
name: PRIMARY_KEY,
type: AttributeType.STRING,
},
stream: StreamViewType.NEW_IMAGE,
removalPolicy: isProd ? RemovalPolicy.RETAIN : RemovalPolicy.DESTROY,
});
// Default props for lambda functions
const nodeJsFunctionProps: NodejsFunctionProps = {
bundling: {
externalModules: [
'aws-sdk', // Use the 'aws-sdk' available in the Lambda runtime
'#sparticuz/chrome-aws-lambda',
],
},
depsLockFilePath: join(__dirname, '../package-lock.json'),
environment: {
PRIMARY_KEY: PRIMARY_KEY,
TABLE_NAME: dynamoTable.tableName,
},
runtime: Runtime.NODEJS_16_X,
};
In the lambda file, I'm getting the variables this way:
const TABLE_NAME = process.env.TABLE_NAME ?? '';
The error:
failed: InvalidParameterType: Expected params.Environment.Variables['TABLE_NAME'] to
be a string
I have created a module 'resources.bicep' to create event hub namespace in two regions.
resource eventHubNamespace 'Microsoft.EventHub/namespaces#2021-11-01' = {
name: resourceName
location: location
sku: {
name:'Standard'
tier:'Standard'
capacity:1
}
}
resource eventHub 'Microsoft.EventHub/namespaces/eventhubs#2021-11-01' = if (shortRegion == 'wus2') {
name: 'city-temprature'
parent: eventHubNamespace
properties: {
messageRetentionInDays: 1
partitionCount: 2
}
}
From the parent bicep file I run the module as
module weatherWest 'resources.bicep' = {
name:'westResources'
scope:resourceGroup('${name}-wus2')
params: {
name: name
shortRegion: 'wus2'
location: 'westus2'
}
}
module weatherEast 'resources.bicep' = {
name:'eastResources'
scope:resourceGroup('${name}-eus2')
params: {
name: name
shortRegion: 'eus2'
location: 'eastus2'
}
}
How do I setup the GeoPairing?
I have not found a way to call Microsoft.EventHub/namespaces/disasterRecoveryConfigs#2021-11-01 from the parent bicep file.
Code is located in this branch
https://github.com/xavierjohn/SearchIndexDisasterRecoverNearRealTime/blob/bicep/bicep/weatherResources.bicep
Per the docs,
you need to specify a parent resource. You can look up an existing resource with the existing keyword.
Something along these lines should work.
resource primary 'Microsoft.EventHub/namespaces#2021-11-01' existing = {
name: 'primaryEventHubName'
resource secondary 'Microsoft.EventHub/namespaces#2021-11-01' existing = {
name: 'secondaryEventHubName'
resource symbolicname 'Microsoft.EventHub/namespaces/disasterRecoveryConfigs#2021-11-01' = {
name: 'foo'
parent: primary
properties: {
alternateName: 'string'
partnerNamespace: secondary.id
}
}
I got help from the Azure Bicep team and currently there is no way to pass a resource as output but they are working on a proposal. For now there is a trick that will work so till the elegant solution comes out,
use existing and set dependsOn on the Geo Pairing fragment.
The end code looks like below.
module allResources 'resources.bicep' = [for location in locations : {
name:'allResources'
scope:resourceGroup('${name}-${location.shortRegion}')
params: {
name: name
shortRegion: location.shortRegion
location: location.region
}
}]
resource primaryEventHubNamespace 'Microsoft.EventHub/namespaces#2021-11-01' existing = {
name: '${name}wus2'
}
resource disasterRecoveryConfigs 'Microsoft.EventHub/namespaces/disasterRecoveryConfigs#2021-11-01' = {
name: name
parent: primaryEventHubNamespace
properties: {
partnerNamespace: resourceId('${name}-eus2', 'Microsoft.EventHub/namespaces', '${name}eus2')
}
dependsOn: [
allResources
]
}
Strange problem.
I have an entity which has property set up by Doctrine loadClassMetadata:
App\EventListener\DrinkEventListener:
arguments:
- { drinkImagesWebPath: '%env(DRINK_IMAGE_WEB_PATH)%', appUrl: '%env(APP_URL)%' }
tags:
- { name: doctrine.event_listener, event: loadClassMetadata }
I changed argument to normal parameter ('%app_url%'), no luck.
DrinkEventListener:
...
public function loadClassMetadata(LoadClassMetadataEventArgs $eventArgs)
{
Drink::$appUrl = $this->appUrl;
Drink::$drinkImageWebPath = $this->drinkImagesWebPath;
}
The problem is, when I clear Symfony cache with warmup, then these properties are empty. Event handler is executed though.
When I clear cache with no-warmup, these properties exist.
I followed the official documentation on testing ngxs selectors (https://ngxs.gitbook.io/ngxs/recipes/unit-testing#testing-selectors), however it doesn't cover how to unittest dynamic selectors created with createSelector.
My normal selector just gets the state as an argument so I can easly test it by passing a prepared state and comparing the output.
#Selector()
static nachweise(state: NachweisStateModel) {
return state.nachweise;
}
//Setup state
const state = {...};
//Compare expectations
expect(NachweisState.nachweise(state)).toEqual(...);
My dynamic selector looks like this:
#Selector()
static nachweisById(id: string) {
return createSelector([NachweisState], state => {
return state.nachweise.find(nachweis => nachweis.id === id);
});
}
The only parameter it gets is the id by which it selects, but not the state. The State is automagically passed in by specifying it as the first parameter to createSelector and I don't know how I should test this selector.
It seems that the documentation has been updated:
it('should select requested animal names from state', () => {
const zooState = {
animals: [
{ type: 'zebra', name: 'Andy'},
{ type: 'panda', name: 'Betty'},
{ type: 'zebra', name: 'Crystal'},
{ type: 'panda', name: 'Donny'},
]
};
const value = ZooSelectors.animalNames('zebra')(zooState);
expect(value).toEqual(['Andy', 'Crystal']);
});